安卓4.2有4 MediaPlayers ="不能播放这段视频" [英] Android 4.2 with 4 MediaPlayers = "Can't play this video"

查看:106
本文介绍了安卓4.2有4 MediaPlayers ="不能播放这段视频"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我试图加载至少4 mediaPlayers,其中一人将损坏的视频它试图加载和触发Android操作系统的消息无法播放此视频

Whenever I'm trying to load at least 4 mediaPlayers, one of them will corrupt the video it's trying to load and trigger an Android OS message "Can't play this video"

其他信息:

有关3 mediaPlayers一切工作正常。

For 3 mediaPlayers everything works fine.

在其他Android版本,不同于4.2,同样的code同为4影视作品。

的4个视频可以独立于设备上播放。没有格式问题。

The 4 video can be played independently on the device. There is no format problem.

启动程序,并得到无法播放此视频的消息后,视频无法再播放任何其他应用程序,除非我重新设置设备。

After starting the program and getting the "Can't play this video" message, the video can no longer be played in any other application unless I reset the device.

我想这既与surfaceViews显示VideoViews或独立MediaPlayers。

I tried this both with VideoViews or independent MediaPlayers displayed on surfaceViews.

我复制到运行的是Android 4.2以上的设备的错误。 在Android 4.1.2及其他Android 4个版本,我不记得了code正常工作。

I replicated the error on more devices running Android 4.2. On android 4.1.2 and other android 4 versions I do not recall the code worked fine.

推荐答案

在Android上,这个想法是,一​​切有关媒体codeCS是从哪个有权使用一致的和独特的API,开发人员隐藏:的 的MediaPlayer

On Android, the idea is that everything related to media codecs is hidden from the developer which has to use a consistent and unique API : MediaPlayer.

当你播放媒体,会是一个流或东西所在的外部设备,水平低codeCS /解析器实例化每一个应用程序将需要他们的帮助的时间。

When you play a media, would it be a stream or something located on the external device, the low level codecs/parsers are instanciated every time an application will be needing their help.

然而,它发生,对相关的硬件解码,有的codeCS特殊原因,不能被实例化一次以上。作为事实上,应用程序的必须的是释放资源(例如codeCS实例)时,他们就不再需要它们通过调用的 MediaPlayer.release() 处于有效状态。

However, it occurs that for particular reasons related to hardware decoding, some codecs, cannot be instantiated more than once. As a matter of fact, every application must be releasing resources (codecs instances for instance) when they do not need them anymore by calling MediaPlayer.release() in a valid state.

其实,我在说什么则说明的 发布 的Andr​​oid开发者网站上的文档:

In fact, what I'm saying is illustrated in the documentation of release on the Android Developers website :

与此MediaPlayer对象相关联的释放资源。它是   好的做法,调用此方法,当您使用大功告成   在MediaPlayer。的应用程序的具体地,每当一个活动   暂停(它的onPause()方法被调用),或停止(它的onStop()   方法被调用),此方法应被调用以释放   MediaPlayer对象,除非应用程序有特殊需要保持   在对象周围。除不必要的资源(如   内存和codeCS实例)召开之际,未能把这种   方法,如果立即MediaPlayer对象不再需要可   也导致连续电池消耗为移动设备,和   对于其他应用程序播放失败,如果没有多个实例   同codeC是在设备上的支持。即使多个实例   支持的同一codeC,一些性能下降可能   预期当不必要多个实例被用于在同一   时间。

Releases resources associated with this MediaPlayer object. It is considered good practice to call this method when you're done using the MediaPlayer. In particular, whenever an Activity of an application is paused (its onPause() method is called), or stopped (its onStop() method is called), this method should be invoked to release the MediaPlayer object, unless the application has a special need to keep the object around. In addition to unnecessary resources (such as memory and instances of codecs) being held, failure to call this method immediately if a MediaPlayer object is no longer needed may also lead to continuous battery consumption for mobile devices, and playback failure for other applications if no multiple instances of the same codec are supported on a device. Even if multiple instances of the same codec are supported, some performance degradation may be expected when unnecessary multiple instances are used at the same time.

所以,无论你是不是叫发布当您完成播放,或者另一个应用程序是抱着对这种资源的参考。

So, either you are not calling release when you are done playing back, or another app is holding a reference on this kind of resources.

编辑:

如果您需要在同一活动渲染几部影片,你有两个选择。正如我在我的回应说,你本来想什么是不可能的,因为低层次的问题,也不是在iOS的方式。

If you need to be rendering several videos on the same Activity, you have two choices. As I said in my response, what you originally wanted is not possible because of low-level issues, neither it is on iOS by the way.

您可以的尝试什么的做的虽然是:

What you can try to do though is :

  • 如果您正在播放的媒体都的没有的实时流式传输的内容,你可以换4的视频成一个单一的,使用广泛可用的免费的视频编辑器之一。然后呈现在你的活动在全屏幕视频,它看起来就像你有4 浏览

  • If the medias you are playing are not real-time streamed content, you could wrap the 4 videos into a single one, using one of the widely available free video editors. Then render the video in full screen in your Activity, it will look like you have 4 Views.

如果他们是实时/非录制的内容,保留的第一的视频原样。我想每一个视频连接使用相同的codeC /箱codeD。你可能会想是到c 3其他视频反$ C $所以他们使用不同的codeC和不同的格式。请确保您转码为codeC /容器是支持的Andr​​oid 。此可能的潜在强制机器人使用不同的去codeRS在同一时间。我认为这是矫枉过正比你期望的结果。

If they are real-time/non recorded content, keep the first video as is. I assume every video is encoded using the same codec/container. What you might be trying is to transcode the 3 other videos so they use a different codec and a different format. Make sure you are transcoding to a codec/container that is supported by Android. This might potentially force Android to use different decoders in the same time. I think this is overkill compared to the result you're expecting.

最后,你可以使用不同的后端解码,如的MediaPlayer + FFMPEG 或只是 FFMPEG 。但同样,即使它的工作原理,这将是,我认为,一个巨大的矫枉过正。

Lastly, you could use a different backend for decoding such as MediaPlayer + FFMPEG or just FFMPEG. But again, even if it works this will be, I think, a huge overkill.

要总结这件事,你不得不做出妥协,以便这个工作。

To sum this up, you have to make compromises in order for this to work.

这篇关于安卓4.2有4 MediaPlayers ="不能播放这段视频"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆