Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorry, this video cannot be played - streaming mp4 to android

Tags:

android

video

I've searched all over for a solution to this (including SO), however still haven't found a solution.

I need to have a simple video playback in my app. It's a bit less straightforward than a simple window with a video. Simplified, I have two layouts on my screen, one containing some other stuff and the other is to have the video window. There's also a button to switch between the two. This all works just fine, after I figured out that the videoview cannot be present on a view with visibility 'gone' - therefore I'm adding/removing it to/from container layout when needed.

However, I have the problem with the actual video playback. When I try to activate it, I get the dreaded error Sorry, this video cannot be played. One of the questions here on SO is discussing video formats (Android -- Can't play any videos (mp4/mov/3gp/etc.)?) - however I already have what seems to be the correct format, with 320px width and everything else. One of the answers on that thread mentions that videos from here "definitely work". I tried a couple from there - but I got another common beast: Sorry, this video is not valid for streaming to this device.

Please note that I'm testing on an actual device, as video playback is not working in the emulator. Also note that the solution must work on Android 1.6 and above (client's requirement). The device I'm testing on is LG GT540 Optimus with Android 2.1 (at present I don't have any other devices available).

From what I figured out, if I don't use qt-faststart on the videos, I get error Sorry, this video is not valid for streaming to this device. If I do use qt-faststart, then I get Sorry, this video cannot be played.

Here's my code for the playback:

VideoViewer videoPlayer = new VideoViewer(this);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoPlayer);
videoPlayer.setMediaController(mediaController);
videoPlayer.setVideoURI(Uri.parse(object.getVideoURL()));
LinearLayout container = (LinearLayout)ObjectInfo.this.findViewById(R.id.VideoContainer);
container.setVisibility(VISIBLE);
container.addView(videoPlayer, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
videoPlayer.requestFocus();
videoPlayer.start();

Now, the video I'm trying to play is to be progressive-downloaded from HTTP: object.getVideoURL() returns http://www.ooklnet.com/files/381/381489/video.mp4

Can anybody please help me sort this out? This is the last thing I need to complete before the whole app is ready.

Many thanks!

Edit: I tried using MediaPlayer - but got even worse results than with VideoView, so went back to VideoView. Now, in simulator, I get a black screen with controls hovering over it and the sound of the video is playing fine, also the progress is adjusting as the playback continues. However on my actual device, I'm still getting Sorry, this video cannot be played. error

like image 934
Aleks G Avatar asked Nov 04 '11 16:11

Aleks G


2 Answers

Turned out the problem was with the format of the videos (specifically, the parameters I used with ffmpeg to create the MP4 videos). I ensured that the videos are baseline H.264 - and everything worked properly. See this question for more details.

like image 96
Aleks G Avatar answered Sep 27 '22 00:09

Aleks G


Maybe you need to change the way you set up your MediaPlayer. I just plugged the url of your sample video into the apidemos example and it worked just fine.

See: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.html

Hope that helps.

like image 33
Damian Avatar answered Sep 26 '22 00:09

Damian