I am beginner in android development and try to play video from link. But it's giving error "sorry,we can't play this video"
. I tried so many links but for all links its show same error.
My code is the following
public class VideoDemo extends Activity {
private static final String path ="http://demo.digi-corp.com/S2LWebservice/Resources/SampleVideo.mp4";
private VideoView video;
private MediaController ctlr;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.videoview);
video = (VideoView) findViewById(R.id.video);
video.setVideoPath(path);
ctlr = new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
}
}
Logcat shows following error message:
04-12 15:04:54.245: ERROR/PlayerDriver(554): HandleErrorEvent: PVMFErrTimeout
String fileUrl = "http://192.168.1.131/myproject/songs/xyz"; String url = "http://myserver/songs/xyz"; //(myserver -> A remote server) mVideoView. setVideoURI(Uri. parse(fileUrl)); mVideoView. requestFocus();
Go to the video you'd like to share. Under the video player, tap Share . Select Copy link, or select an app to share the link directly via that app.
It has something to do with your link and content. Try the following two links:
String path="http://www.ted.com/talks/download/video/8584/talk/761";
String path1="http://commonsware.com/misc/test2.3gp";
Uri uri=Uri.parse(path1);
VideoView video=(VideoView)findViewById(R.id.VideoView01);
video.setVideoURI(uri);
video.start();
Start with "path1", it is a small light weight video stream and then try the "path", it is a higher resolution than "path1", a perfect high resolution for the mobile phone.
Try this:
String LINK = "type_here_the_link";
setContentView(R.layout.mediaplayer);
VideoView videoView = (VideoView) findViewById(R.id.video);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
pDialog = new ProgressDialog(this);
// Set progressbar message
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
// Show progressbar
pDialog.show();
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(mVideoView);
Uri videoUri = Uri.parse(videoUrl);
mVideoView.setMediaController(mediacontroller);
mVideoView.setVideoURI(videoUri);
} catch (Exception e) {
e.printStackTrace();
}
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
mVideoView.start();
}
});
mVideoView.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
if (pDialog.isShowing()) {
pDialog.dismiss();
}
finish();
}
});
You can do it using FullscreenVideoView
class. Its a small library project. It's video progress dialog is build in. it's gradle is :
compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.0'
your VideoView xml is like this
<com.github.rtoshiro.view.video.FullscreenVideoLayout
android:id="@+id/videoview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
In your activity , initialize it using this way:
FullscreenVideoLayout videoLayout;
videoLayout = (FullscreenVideoLayout) findViewById(R.id.videoview);
videoLayout.setActivity(this);
Uri videoUri = Uri.parse("YOUR_VIDEO_URL");
try {
videoLayout.setVideoURI(videoUri);
} catch (IOException e) {
e.printStackTrace();
}
That's it. Happy coding :)
If want to know more then visit here
Edit: gradle path has been updated. compile it now
compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.2'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With