Android MediaPlayer - 有时即使播放音频也不会播放视频

发布于 2024-12-06 01:34:59 字数 1900 浏览 1 评论 0原文

我正在开发一个 Android 应用程序,并使用 Android SDK 的 MediaPlayer 在我的应用程序中播放一些视频。当我在应用程序中播放视频时,大约五分之一的时间是播放音频而不播放视频。这不是一个简单的编码错误,因为大多数时候视频都能完美播放。

我认为我的代码中的竞争条件导致了该错误。但是,我添加了一些调试语句,当视频不播放时,一切似乎都设置正确。

我扫描了网络并试图找到解决方案,但没有一个是足够的(见下文)。

以前有人遇到过此类问题吗?如果是这样,你做了什么?

类似问题

MediaPlayer 视频未播放

android 媒体播放器显示音频但不显示视频

android 视频,听到声音但没有视频

更多详细信息:< /strong>

  • 我在两部手机上都遇到过这个错误。在 Samsung Charge 上,视频的播放时间为 80%,20% 的时间有音频但没有视频。在 T-Mobile Comet 上情况更糟;视频仅播放大约 10% 的时间。
  • 这不是文件的问题,我尝试了各种视频文件和编解码器并遇到了相同的问题。
  • 不是存储介质的问题。我尝试播放存储在内部存储和 SD 卡上的视频,两者都没有什么区别。我什至尝试在播放之前读取一些文件,希望系统能够缓存它,但这似乎也没有帮助。

更新:

我一直在调试这个并通过 logcat 查看。我发现当视频工作时,logcat 中会出现类似以下内容:

09-28 00:09:03.651: VERBOSE/PVPlayer(10875): setVideoSurface(0x65638)

但是当视频不播放时,看起来有一个空条目:

09-28 00:03:35.284: VERBOSE/PVPlayer(10875): setVideoSurface(0x0)

更新 2:

当视频无法播放时,带有参数 what==MEDIA_ERROR_UNKNOWN(0x1)extra==35 的函数 MediaPlayer.OnInfoListener。我查看了 Android 代码库,试图确定未知错误 35 的含义。我发现了文件 pv_player_interface.h,它表明错误代码 35 对应于称为 PVMFInfoTrackDisable 的内容。我用谷歌搜索了这个术语,找到了一个名为 pvmf_return_codes.pdf 的文件。该文件给了我以下难以理解的解释:

4.34。 PVMFInfoTrackDisable

特定曲目的通知 禁用。这是基于每首曲目的。对于未压缩的 音频/视频格式,在选择可用曲目的过程中 在内容中,如果解码器不支持该曲目,则会出现 发送 PVMFInfoTrackDisable 事件。如有需要,该活动将在 每个曲目发送一次。

我觉得我已经走了很长一段路,但距离找到答案还很远……仍在调查中。

I am developing an Android App and I'm using the Android SDK's MediaPlayer to play some videos in my app. When I play the video in my app, about one out of five times, the audio plays without video. It's not a simple coding error because most of the time the video plays perfectly.

I have considered that a race condition in my code caused the bug. However, I added a number of debug statements and everything seems to be set up properly when the video does not play.

I have scanned the web and SO trying to find solutions but none have been adequate (see below).

Has anyone run into this type of problem before? If so, what did you do?

Similar Questions:

MediaPlayer Video not played

android media player shows audio but no video

android video, hear sound but no video

Some More Details:

  • I've come across this bug on two phones. On a Samsung Charge video plays 80% of the time and 20% of the time there's audio but no video. On a T-Mobile Comet it's much worse; video only plays about 10% of the time.
  • It's not a problem with the file, I've tried various video files and codecs and get the same issues.
  • It's not a problem with the storage medium. I've tried playing the video when it was stored on internal storage and the sdcard, neither makes a difference. I have even tried reading some of the file before playing it, hoping that the system will cache it, but that doesn't seem to help either.

Update:

I've been debugging this and looking through logcat. I've found that when the video works, something like the following appears in logcat:

09-28 00:09:03.651: VERBOSE/PVPlayer(10875): setVideoSurface(0x65638)

But when video doesn't play, it looks like there's a null entry:

09-28 00:03:35.284: VERBOSE/PVPlayer(10875): setVideoSurface(0x0)

Update 2:

When the video fails to play, the function MediaPlayer.OnInfoListener with parameters what==MEDIA_ERROR_UNKNOWN(0x1) and extra==35. I looked through the Android code-base to try to determine what unknown error 35 means. I came across the file pv_player_interface.h, which indicates that error code 35 corresponds to something called a PVMFInfoTrackDisable. I googled that term which brought me to a file called pvmf_return_codes.pdf. That file gave me the following unintelligible explanation:

4.34. PVMFInfoTrackDisable

Notification that paticular track is
disable. This one is on a per track basis. For uncompressed
audio/video formats, during the process of selecting tracks available
in content, if the decoder doesn't support the track, a
PVMFInfoTrackDisable event is sent. The event, if necessary, will be
sent once per track.

I feel like I've gone a long way, but am no closer to finding an answer... still investigating.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

那片花海 2024-12-13 01:34:59

我解决了这个问题,尽管是以一种完全黑客的方式。实际上有两个问题:

  1. 邪恶信息 35 消息: 我发现有时 MediaPlayer.OnInfoListener 会被调用 extra==35。发生这种情况时,您就完蛋了,视频将无法正常播放。我不知道是什么原因造成的。我发现的唯一修复方法是尝试重新启动视频并重新执行整个prepareAsync 过程。视频播放通常第二次就可以了。

  2. 未设置视频大小:即使在 MediaPlayer.OnPreparedListener 发出(或等效的 prepare() 返回)后,也可能无法设置视频大小。视频大小通常会在准备返回后几毫秒内设置,但有一会儿它处于模糊状态。如果在设置视频大小之前调用 MediaPlayer.start(),则播放有时(但并非总是)会失败。有两种可能的解决方案:(1) 轮询 MediaPlayer.getVideoHeight() 或 getVideoWidth() 直到它们非零,或者 (2) 等待直到调用 OnVideoSizeChangedListener。仅在这两个事件之一之后,才应调用 start()。

通过这两项修复,视频播放更加一致。这些问题很可能是我的手机(Samsung Charge 和 T-Mobile Comet)的错误,因此如果其他手机上存在不同但类似的问题,我不会感到惊讶。

I solved the problem, albeit in a totally hackish way. There are two problems actually:

  1. The Evil Info 35 Message: I found that occasionally MediaPlayer.OnInfoListener will get called with extra==35. When this happens, you're screwed and the video will not play properly. I have no idea what causes it. The only fix I found was to try restarting the video and going through the whole prepareAsync process over again. Video playback usually works the second time.

  2. Video Size Not Set: Even after MediaPlayer.OnPreparedListener gets issued (or equivalently prepare() returns) the video size may not be been set. The video size will usually be set a couple of miliseconds after prepare returns, but for a few moments it is in a nebulous state. If you call MediaPlayer.start() before the video size is set, then playback will sometimes (but not always) fail. There are two potential solutions to this: (1) poll MediaPlayer.getVideoHeight() or getVideoWidth() until they're non-zero or (2) wait until OnVideoSizeChangedListener is called. Only after one of these two events, should you call start().

With these two fixes, video playback is much more consistent. It's very likely that these problems are bugs with my phones (Samsung Charge and a T-Mobile Comet) so I won't be surprised if there are different, but similar problems on other phones.

爱本泡沫多脆弱 2024-12-13 01:34:59

根据 speedplane 的建议,我想出了以下代码。如果 MediaPlayer.getVideoHeight() 在 onPrepared 中返回 0,那么我会延迟 1 秒,然后重试。现在,如果第一次不播放,通常会在 1 秒后播放。我已经看到它需要多次尝试。

   private void videoPlayer(String path){
      if (mMediaController == null)
      {
         mMediaController = new MediaController(this);
         mVideoView.setMediaController(mMediaController);
      }
      if (!mMediaController.isShowing())
         mMediaController.show();

      getWindow().setFormat(PixelFormat.TRANSLUCENT);
      mVideoView.setVideoPath(path);
      mVideoView.requestFocus();
      mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
               public void onPrepared(final MediaPlayer mp) {
               mVideoView.seekTo(mImageSeek);
               if (mp.getVideoHeight() == 0) {
                  final Handler handler = new Handler();
                  handler.postDelayed(new Runnable() {
                        @Override
                           public void run() {
                           mVideoView.stopPlayback();
                           mMediaController = null;
                           videoPlayer(mImageFilepath);
                        }
                     }, 1000);
               } else 
                  mVideoView.start();
            }
         });
   }

Following speedplane's suggestions I came up with the following code. If the MediaPlayer.getVideoHeight() returns 0 in onPrepared then I delay for 1 second and try again. Now if it does not play the first time it usually will play 1 second later. I have seen it take several tries though.

   private void videoPlayer(String path){
      if (mMediaController == null)
      {
         mMediaController = new MediaController(this);
         mVideoView.setMediaController(mMediaController);
      }
      if (!mMediaController.isShowing())
         mMediaController.show();

      getWindow().setFormat(PixelFormat.TRANSLUCENT);
      mVideoView.setVideoPath(path);
      mVideoView.requestFocus();
      mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
               public void onPrepared(final MediaPlayer mp) {
               mVideoView.seekTo(mImageSeek);
               if (mp.getVideoHeight() == 0) {
                  final Handler handler = new Handler();
                  handler.postDelayed(new Runnable() {
                        @Override
                           public void run() {
                           mVideoView.stopPlayback();
                           mMediaController = null;
                           videoPlayer(mImageFilepath);
                        }
                     }, 1000);
               } else 
                  mVideoView.start();
            }
         });
   }
寻找我们的幸福 2024-12-13 01:34:59

我已经研究这个bug 2周了,我或多或少地了解了真正的问题。当然,我说的是邪恶信息35消息。如果您遇到了这个奇妙的奇怪错误,现在您可以高兴地拍摄一些像三星这样的供应商:D ...

问题的出现是因为用户无法看到表面视图(tabhost 中的活动或暂停-唤醒功能,有时不在焦点上,有时也不在前面(也许))。

这是因为当某些人重置该视频时它运行正常,导致它获得焦点或者另一个活动/对象可能没有重叠它。

当发生其中一些情况时,媒体播放器会认为您看不到视频或无法播放视频,并禁用视频轨道,让您在听音乐时成为工作生活中最头痛的事情。

将看到下一个错误,祝你好运。 :D

I have been studying this bug 2 weeks , and i have understand more or less the real problem . Of course i'm talking about The Evil Info 35 Message . If you have met this wonderfull strange error , now you can be happy and shot some vendors like samsung :D ...

The problem comes cause the surface view can't be seen by the user (activity in tabhost or pause-wakeup function , not in focus sometimes , not in front sometimes too (maybe)).

That's cause when some reset that video it runs ok , cause it gains focus or maybe another activity/object is not overlapping it.

When some of those happen , the mediaplayer thinks you can't see the video or it can't play , and it disable video track, giving you the worst headache in your worklife while listening the music track.

Will see next bug , good luck . :D

煮茶煮酒煮时光 2024-12-13 01:34:59

我的 Desire HD 也遇到过这个问题大约一两次。我尝试了很多方法,但错误始终存在。毕竟我选择在我的设备上安装自定义 ROM。后来它工作得很好,我再也没有遇到过这个问题。

我知道这不是您想听到的那种答案,但我没有找到其他答案。

在这里您可以找到适合您设备的自定义 rom:XDA 开发人员

我希望我能帮助您。

最好的问候和快乐的电影观赏

之旅 =)

I had that problem too on my Desire HD about 1 or 2 times. I tried many things but the error was allways there. Afterall i choosed to install a custom rom on my device. Afterwards it worked perfectly and I never had a this issue again.

I know its not that kind of answer you'd like to hear but i didn't find an other soultions.

Here you find custom roms for your device: XDA Developers

I hope I could help you out.

Best Regards and Happy Movie watching

safari =)

疧_╮線 2024-12-13 01:34:59

根本问题是:
在surfaceCreated调用你开始视频播放之前,当持有MediaPlayer时还没有准备好,这样你只能听到声音而看不到图像!

正确的方法是:

The fundamental question is:
before surfaceCreated invoked you start video playback, when the holder is not ready for MediaPlayer, so that you only hear the sound but can not see the picture!

The right way is:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文