简体   繁体   English

对不起,此视频无法播放 - 将mp4流式传输到android

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

I've searched all over for a solution to this (including SO), however still haven't found a solution. 我已经搜遍了这个(包括SO)的解决方案,但仍然没有找到解决方案。

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. 当我尝试激活它时,我收到了可怕的错误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. 关于SO的一个问题是讨论视频格式( Android - 无法播放任何视频(mp4 / mov / 3gp /等)? ) - 但是我已经拥有了正确的格式,宽度为320像素,其他一切。 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. 我从那里尝试了几个 - 但我有另一个常见的野兽: 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). 另请注意,该解决方案必须适用于Android 1.6及更高版本(客户端的要求)。 The device I'm testing on is LG GT540 Optimus with Android 2.1 (at present I don't have any other devices available). 我正在测试的设备是带有Android 2.1的LG GT540 Optimus(目前我没有任何其他设备可用)。

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. 根据我的想法,如果我不在视频上使用qt-faststart ,我会收到错误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. 如果我确实使用qt-faststart ,那么我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 现在,我正在尝试播放的视频是从HTTP逐步下载的: object.getVideoURL()返回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. 编辑:我尝试使用MediaPlayer - 但结果比使用VideoView更糟,所以回到了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. 但是在我的实际设备上,我仍然Sorry, this video cannot be played. error 错误

Turned out the problem was with the format of the videos (specifically, the parameters I used with ffmpeg to create the MP4 videos). 原来问题在于视频的格式(具体来说,我用ffmpeg创建MP4视频的参数)。 I ensured that the videos are baseline H.264 - and everything worked properly. 我确保视频是baseline H.264 - 一切正常。 See this question for more details. 有关详细信息,请参阅此问题

Maybe you need to change the way you set up your MediaPlayer. 也许你需要改变你设置MediaPlayer的方式。 I just plugged the url of your sample video into the apidemos example and it worked just fine. 我只是将您的示例视频的网址插入到apidemos示例中,它运行得很好。

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

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM