I have a VideoView that works with a lot of devices but not on others. For some time it shows my ProgressDialog and then it fires a Popup that says Impossible to play video (translated from Italian, so it may be different but... you understand).
For example it works on Samsung Galaxy S:
Android version: 2.2.1
Kernel version: 2.6.32.9
But not on HTC Magic
Android version: 2.2
Kernel version: 2.6.34.5
The video I want to show is taken from a URL and it'an MP4 file.
Here's the code:
public class VideoViewActivity extends BaseActivity {
ProgressDialog progDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri videoUri = Uri.parse(getIntent().getStringExtra("url"));
setContentView(R.layout.activity_video_view);
VideoView vv = (VideoView) findViewById(R.id.videoView);
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.setVideoURI(videoUri);
vv.start();
if (app.isEnglish()) {
progDialog = ProgressDialog.show(this, getResources().getString(R.string.en_wait), getResources().getString(R.string.en_load), true);
}
else {
progDialog = ProgressDialog.show(this, getResources().getString(R.string.it_wait), getResources().getString(R.string.it_load), true);
}
progDialog.setCancelable(true);
vv.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progDialog.dismiss();
}
});
}
}
That's the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".VideoViewActivity" >
<VideoView
android:id="#+id/videoView"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Any suggestions?
I too had the same iisue while using videoView. I managed it using device's installed media application using intent. They are doing there application for managing media, Why we want to waste our time...
PackageManager packageManager = getPackageManager();
Intent videoIntent = new Intent(Intent.ACTION_VIEW);
videoIntent.setDataAndType(Uri.parse(videoUrlLink),
"video/*");
List listOfSuppApps = packageManager
.queryIntentActivities(videoIntent,
PackageManager.MATCH_DEFAULT_ONLY);
if (listOfSuppApps.size() <= 0) {
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.No_supported_applications_Installed),
Toast.LENGTH_LONG).show();
} else {
Intent intnt = new Intent(Intent.ACTION_VIEW);
intnt.setDataAndType(Uri.parse(urlLink), mediaType+"/*");
context.startActivity(intnt);
}
The above is my code
Related
Android app gives the alert on the top of playing video with vitamio
Vitamio on Android 7.0 - Detected problems with app native libraries,
libffmpeg.so: text relocations
I'm using latest version of vitamio
compile 'com.charonchui.vitamio:vitamio:4.2.2'
and simple code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setImmersiveFullScreen();
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.activity_main);
String URL = "ANY URL HERE";
final VideoView mVideoView = (VideoView)
findViewById(R.id.surfaceView);
HashMap<String, String> options;
mVideoView.setVideoURI(Uri.parse(URL));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
mVideoView.setOnPreparedListener(new
MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
}
It gives this alert and then continues to play video perfectly, but I can't find a way to disable this alert and get this app in production.
Any help will be appreciated, thanks.
I'm trying to play a live RTSP video (from rtsp://IP_ADDR:554/user=admin&password=admin&channel=&stream=.sdp?real_stream--rtp-caching=100) using android VideoView, and here's my code:
public class TestCamera3 extends Activity {
private VideoView mVideoView;
private String videoAddress;
private static final String TAG = "videoTest";
private String keyValue = "videoAddress";
private String defaultAddress = "rtsp://IP_ADDR:554/user=admin&password=admin&channel=&stream=.sdp?real_stream--rtp-caching=100";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
SharedPreferences prefs = this.getSharedPreferences(TAG, 0);
videoAddress = prefs.getString(keyValue, defaultAddress);
mVideoView = (VideoView) findViewById(R.id.video);
PlayRtspStream(defaultAddress);
}
private void PlayRtspStream(String rtspUrl) {
// mVideoView.setVideoPath(rtspUrl);
mVideoView.setVideoURI(Uri.parse(rtspUrl));
mVideoView.requestFocus();
mVideoView.setMediaController(new MediaController(this));
mVideoView.start();
}}
& activity_main.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<VideoView
android:id="#+id/video"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</VideoView>
So when i tested this code in Samsung Note 4 v4.2.2 (Jelly Bean) & Nexus 5 v5.0 (Lollipop) .. it's worked well but when i tested it in Galaxy tab 3 v4.1.2 (Jelly Bean) it's display message (Can't Play this Video)
Can any one tell me why this ?
I want to play a streaming video in android from a website.
For example, I want to play the streaming video from this url: http://florotv.com/canal2.html
Using URL Helper, I have been able to capture the rtmp URL that it's
rtmp://198.144.153.139:443/kuyo<playpath>ver44?id=acf6f5271f8ce567ed6c8737ce85a044&pid=32342e3136362e37332e323139 <swfUrl>http://yukons.net/yplay2.swf <pageUrl>http://yukons.net/embed/37363635373233343334/eeff74c57593ca38defc902fa6d88005/600/400
Now that I have this URL, I wanna know if it's possible to play the video in android.
I have tried this but it doesn't work because I don't know how to set the swfUrl, pageUrl.....
private static final String MOVIE_URL="rtmp://198.144.153.139:443/kuyo";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(MOVIE_URL);
intent.setData(data);
startActivity(intent);
Thanks in advance....
Add below code into your Activity.java file.
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.videoPlayer);
try {
String link="http://videocloud/video.mp4";
VideoView videoView = (VideoView) findViewById(R.id.myVideoView);
final ProgressBar pbLoading = (ProgressBar) findViewById(R.id.pbVideoLoading);
pbLoading.setVisibility(View.VISIBLE);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
pbLoading.setVisibility(View.GONE);
}
});
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}
}
If you don't need MediaController set it to null videoView.setMediaController(null)
I don't think it's enough to just create an intent, you also have to create a context for the video to be played : Like a VideoView object.
The link below has a suggestion for this pattern :
http://androidcodeexamples.blogspot.sg/2011/08/how-to-play-mp4-video-in-android-using.html
Essentially a MediaController object is created with the VideoView object. Then the VideoView is used to start the operation once the URI is set.
Edit :
Probably the main problem though is that your URL contains POST parameters and isn't exactly a unique identifier of a resource (in this case a video file).
The 'swfUrl' and 'pageUrl' parameters are most likely unique to the server that's providing you the page.
You can use Vitamio library for android, where you can set the swfUrl and pageUrl.
Here is a tutorial for it.
I have a simple button, and I wish to play an URL video buy clicking on this button but without a videoView.
So if I click on the button , the phone will ask which internal player I'll choose to play the video.
Here I was using a videoView that was playing the video inside the window of my application but I want it outside :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
video = (VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);
Uri chemin = Uri.parse("http://commonsware.com/misc/test2.3gp");
video.setVideoURI(chemin);
video.start();
Thank you,
so here's the code :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
boutonVideo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent in;
if (v.getId() == R.id.boutonVideo) {
in = new Intent(Intent.ACTION_VIEW, Uri
.parse(urlBandeAnnonce));
startActivity(in);
}
}
});
But it return me an error when I decide to stop the video and return to my activity.
Here is the AndroidRunTime Error :
java.lang.RuntimeException: Unable to start activity
ComponentInfo{Activity}: java.lang.NullPointerException
09-30 15:20:16.449: E/AndroidRuntime(2301):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
Solved
So I add finish(); and the error disappear.
Use an Intent with ACTION_VIEW along with the URI to the movie you want to play:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
startActivity(intent);
where movieUrl is a string containing the path to the movie.
This may or may not work with internet streams. Haven't tried it with those personally.
Have you looked to Android Api examples
if you have installed the samples on your pc it is located at (for windows systems)
C:\Program Files\Android\android-sdk\samples\android-16\ApiDemos\src\com\example\android\apis\media
I am placed video MP4 to my domain space. I have its public URL, Now i want to play it in my android app; but don't know how can I do this. I used following code which is not working. Track controller is moving but I can't see any video on screen.
public class MPlayer extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playvideo);
VideoView videoView = new VideoView(MPlayer.this);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(Uri.parse("http://www.semanticdevlab.com/abc.mp4"));
videoView.requestFocus();
videoView.start();
LinearLayout l = (LinearLayout)findViewById(R.id.mplayer);
l.addView(videoView);
}
}
The VideoView class can load images from various sources (such as resources or content providers), takes care of computing its measurement from the video so that it can be used in any layout manager, and provides various display options such as scaling and tinting.
Code:
videoView = (VideoView)findViewById(R.id.ViewVideo);
videoView.setVideoURI(Uri.parse(“android.resource://” + getPackageName() +”/”+R.raw.video));
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();
if you want see source code : Play video file using VideoView in Android
Most of the time, I'm using following code:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
mp.start();
for more information look at this page: http://developer.android.com/guide/topics/media/index.html
and
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.html
I think this may help you find some solution.
mp=new MediaPlayer();
mp.setDataSource(path);
mp.setScreenOnWhilePlaying(true);
mp.setDisplay(holder);
mp.prepare();
mp.start();
If you are trying this in your emulator, you might have to try it in a real device, because sometimes I too use face the same problem. I will not be able to view the video in emulator, but the video will play without any problem in the mobile. the problem is, I think with the emulator, not with your code.
This is how I played a video file from Network in my project
Required Kotlin, AndroidX
Show a loading dialog while the file is buffering and then start playback:
private fun playVideo(videopath: String) {
Log.e("Playing Video File: ", "" + videopath);
try {
//Show Loader
val builder: AlertDialog.Builder = AlertDialog.Builder(this#ScreenCaptureImageActivity);
builder.setCancelable(false); // if you want user to wait for some process to finish,
builder.setView(R.layout.layout_loading_dialog);
progressDialog = builder.create();
//add Controller
val mediaController = MediaController(this#ScreenCaptureImageActivity);
videoView.setMediaController(mediaController)
//Add URI
//Uncomment to play from local path
//videoView.setVideoURI(Uri.parse(videopath))
//Example Play from Internet
videoView.setVideoPath("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4")
videoView.setOnPreparedListener {
progressDialog!!.dismiss();
//Start Playback
videoView.start()
Log.e(TAG, "Video Started");
}
} catch (e: Exception) {
progressDialog!!.dismiss();
Log.e(TAG, "Video Play Error :" + e.localizedMessage);
}
}
Loader XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<ProgressBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:gravity="center"
android:text="Please wait! This may take a moment." />
</LinearLayout>
**For Network Access add network config in the manifest, from ANdroid P its required **
<application
...
android:networkSecurityConfig="#xml/network_security_config"
>
Add network_security_config.xml in res/xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
You should do it in onResume, because in onCreate VideoView does not knows its size and can't create properly surface to display video.
public class MPlayer extends Activity{
VideoView videoView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playvideo);
videoView = new VideoView(MPlayer.this);
videoView.setMediaController(new MediaController(this));
LinearLayout l = (LinearLayout)findViewById(R.id.mplayer);
l.addView(videoView);
}
#Override
protected void onResume() {
super.onResume();
videoView.setVideoURI(Uri.parse("http://www.semanticdevlab.com/abc.mp4"));
videoView.start();
}