8

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

Community
  • 1
  • 1
Aleks G
  • 56,435
  • 29
  • 168
  • 265
  • How do you set up your URL from your server to play the video?? I need my URL to play my video just like your but its not working :( If i use your video in my browser or Android app it works perfectly. If i try my URL (http://XXX.XXX.XXX.XXX/srv/ProductVideos/lazar108@hotmail.com/s/s_7s.MP4) it doesnt work – Lazar Kukolj Mar 29 '16 at 00:12

2 Answers2

7

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.

Community
  • 1
  • 1
Aleks G
  • 56,435
  • 29
  • 168
  • 265
  • can I have the url which you were playing? I am stuck in a similar issue and not able to play the video in my samsung galaxy 551 having OS 2.2. Please give me your url link for testing. Thanks – Rashmi.B Dec 29 '11 at 06:03
  • @Rashmi.B Here's one that plays perfectly fine on my LG phone: http://www.ooklnet.com/files/368/368007/video.mp4 – Aleks G Dec 29 '11 at 20:28
  • @Aleks G, i am trying to play a .move url which is redirected to .3gp url or sometimes .mp4 URL. Galaxy s v2.3.x playes the .mov url but for any other devices (4.01, 2.2 or any other except 2.3.x) i first have to get the redirected rtsp url to play the video. The redirected rtsp url also randomly plays. Could you suggest some solution? also how to baseline videos in accordance to mobile's compatibility? – Usama Sarwar May 17 '12 at 15:28
  • @UsamaSarwar I'm not sure how you're handling the redirect. Ideally you should let MediaPlayer handle it. Witih RTSP 4GP videos, I found that they most of the times do not play in emulator, but play fine on the actual device. As for the 'baseline' mp4 videos, I used `-profile baseline` on the FFMPEG command line when transcoding the videos. – Aleks G May 17 '12 at 15:36
  • @Aleks G, Thak you for an early response, the redirection is handled by v2.3.x only in my case, if i pass the redirected URL to media play in any other version then it gets played, but it does not play the non-redirected URL. About -profile baseline, i absolutely have no idea how to adjust format of a live streaming video. could you paste a code snipt to baseline a live steraming video to android supported format? – Usama Sarwar May 18 '12 at 10:25
  • @UsamaSarwar You can't do that easily on the fly. In my case I am controlling the videos at the time they are uploaded to my server - so I'm recoding them there - and stream them in the correct format. – Aleks G May 18 '12 at 10:37
  • You can use "mp4box -info" to check the profile of your video. (http://www.videohelp.com/tools/mp4box) – mhenry1384 Jul 11 '12 at 18:26
  • Aleks can you please suggest a solution for the issue i am facing currently? I am able to play video in >2.2 android versions but not in android 2.1 and android 2.2, giving messages **"Can't play video => Sorry, this video is not valid for streaming to this device"**. FYI, i am trying to play video: http://technotalkative.com/user_uploads/mp4_live.mp4 , please check and suggest a solution. – Paresh Mayani Nov 07 '12 at 07:27
  • @PareshMayani I would suggest that you run the video through `qt-faststart`; it usually helped me with this error message. – Aleks G Nov 07 '12 at 09:39
  • @AleksG Thank you for quick reply. Now, you know i have tried `qt-faststart mp4_live.mp4 newOutputFile.mp4`, and i have uploaded output file to my server and try to load in android, but now getting **Sorry, this video cannot be played**. Its being loaded successfully in >2.2 version but not in 2.1 and 2.2 – Paresh Mayani Nov 07 '12 at 11:18
  • @PareshMayani Are you testing on emulator or actual devices? There are lots of known issues with emulator where a video wouldn't play but plays fine on a physical device. I don't have a physical 2.1 device on hand to test (just yesterday reflashed my older 2.1 phone with 2.3). If this is not the case, then check how you encode that video. Check the question/answer linked from this answer. – Aleks G Nov 07 '12 at 12:16
  • @AleksG Yes i am testing on real devices having 2.1, 2.2, 2.3.6, 4.0 and 4.1 (including tablets and phone). As i said its playing fine in >2.3 versions but not in <2.2 version. – Paresh Mayani Nov 07 '12 at 13:05
1

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.

Damian
  • 8,062
  • 4
  • 42
  • 43
  • This example uses MediaPlayer, while I was trying to use VideoView. I guess, I'll try using MediaPlayer instead and see what happens then. – Aleks G Nov 04 '11 at 16:54