42

I'm confused about how VideoView can be used to play video: from a local file, as progressive download and streaming.

This example work for me (on 1.5 and 2.0 at least) by downloading the file and playing it locally.

But is it necessary to download the video before playing: is it possible to play video as progressive download, or by streaming, simply by using setVideoPath or setVideoURI, as in VideoViewDemo in the API samples?

The VideoViewDemo code suggests using setVideoURI for streaming, but I'm not clear what kind of URL I should be using. Does someone have an example URL for a video that can be streamed to the Android emulator using the VideoViewDemo code?

Can progressive download be used with VideoViewDemo? I get a 'sorry, this video cannot be played' message using setVideoPath with URLs that work fine with the blog example linked to above.(Is this a problem in the emulator? I've tried 1.5 and 2.0.)

I've found a lot of examples and documentation online but, so far, nothing that really answers this question.

Sam Dutton
  • 14,775
  • 6
  • 54
  • 64
  • There is a good tutorial [here](http://innovator.samsungmobile.com/cms/cnts/knowledge.detail.view.do?platformId=1&cntsId=9540), which guides you step by step and lists known issues and limitations – Moshe Kravchik Oct 25 '11 at 08:41
  • @MosheKravchik - the link no longer works. Any update? – JohnnyLambada Jan 30 '13 at 19:11
  • @Sam Dutton: Are you able to stream video progressively(parallel downloading and playing)? To check whether progressive streaming works with video, i am downloading half video and playing downloaded half video but this approach says same error as yours **can't play this video**. So how do we stream video in android progressively without using VideoView **setVideoURI** or **setVideoPath**? – Mahantesh M Ambi Jul 18 '14 at 06:35

3 Answers3

20

is it possible to play video as progressive download, or by streaming, simply by using setVideoPath or setVideoURI, as in VideoViewDemo in the API samples?

It should. It certainly works with MediaPlayer, and VideoView is just a ~200 line wrapper around MediaPlayer and a SurfaceView.

The VideoViewDemo code suggests using setVideoURI for streaming, but I'm not clear what kind of URL I should be using.

http:// and rtsp:// can work, if the video was encoded properly.

Does someone have an example URL for a video that can be streamed to the Android emulator using the VideoViewDemo code?

This video works with MediaPlayer, except on the Nexus One.

EDIT: Actually, that link works with the Nexus One as well.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • The following page has several mp4 files can be used as test URIs for Android video streaming: http://people.sc.fsu.edu/~jburkardt/data/mp4/mp4.html – Peter Ajtai Nov 25 '11 at 00:00
  • 1
    can you give me some url to play progressive download.In your link i am not able to find url – Tofeeq Ahmad Mar 19 '12 at 10:52
  • I have encoded the file to be streamable progressively from a URL. Check my answer at http://stackoverflow.com/questions/2592816/auto-launch-the-video-player-in-android-from-the-browser-like-an-iphone-does/2593846#2593846 – hnviet Jun 19 '12 at 05:45
2

It works for simple cases, but only when it is not required to make some custom preparations for requests to get a stream.

This tutorial shows an example of manual streaming emulation for an audio but it can be a little refactored to play video:

http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/

(be sure to use FileDescriptor when setting dataSource, the API was changed slightly from those times).

shaman.sir
  • 3,198
  • 3
  • 28
  • 36
  • 1
    I followed that blog and it works only for audio files. It doesn't work for video file, To check whether progressive streaming works or not i wrote a sample program where it will download only half video and start playing half downloaded video file, it gives error message saying **can't play this video**. – Mahantesh M Ambi Jul 18 '14 at 06:40
  • 1
    Same here. Outdated I guess. – Léon Pelletier Oct 26 '15 at 02:56
  • Link to blog.pocketjourney.com out of date – mmaitlen Oct 19 '17 at 19:09
  • The answer is itself hugely outdated. However, if you are OK with 7-year old code, here's the example how I used it at that time: https://github.com/shamansir/vimeoid/blob/master/apk/src/org/vimeoid/media/VimeoVideoPlayingTask.java – shaman.sir Oct 20 '17 at 11:43
-4

VideoView can only Stream 3gp videos but i recommend this code to stream your video

public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.main);
String videourl = "http://something.com/blah.mp4";
Uri uri = Uri.parse(videourl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setDataAndType(uri, "video/mp4");
startActivity(intent);
}

Or Click here to watch Android Video Streaming Tutorial.