Android MediaPlayer:准备好的视频需要250毫秒才能开始播放 [英] Android MediaPlayer: prepared video takes 250ms to start playing

查看:269
本文介绍了Android MediaPlayer:准备好的视频需要250毫秒才能开始播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我播放视频时,使用prepareAsync(),然后在准备视频时调用start(),从我的start()调用到视频实际开始播放大约需要250毫秒.就是这样吗,还是有趣的事情在这里发生?请注意,视频位于原始目录中.在我的活动的OnCreate中,我有:

When I play a video, using prepareAsync(), then calling start() when the video is prepared, it takes about 250ms from my start() call to when the video actually starts to play. Is that just how it is, or is something funny going on here? Note that the video is in the raw directory. In my activity's OnCreate I have:

private VideoView vv;
private MediaPlayer mp = new MediaPlayer();
vv = (VideoView)findViewById(R.id.vv);
vv.getHolder().addCallback(this);
mp.reset();
mp.setDisplay( vv.getHolder() );
mp.setDataSource( this, Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.moviename) );
Log.d(TAG,"video is preparing");
mp.prepareAsync();

然后是听众:

@Override
public void onPrepared(MediaPlayer arg0) {
   Log.d(TAG, "video is prepared");
   mp.start();
}

实际上,我的代码比这更复杂.用户单击按钮以播放视频,也可以选择其他视频.我有一个隐藏视频的图像,并且从mp.start()开始经过一定的毫秒数后,我将该图像拉开并显示了视频.在我的设备上,我必须将其设置为250ms,以便可靠地不显示视频以外的其他东西(某些东西是黑色的或上一个视频播放的最后一帧).

Actually my code is more complicated than this. The user clicks a button to play the video and can also select different videos. I have an image hiding the video, and at a certain number of ms from mp.start() I pull this image away and reveal the video. On my device I have to set this at 250ms to reliably not reveal something other than the video (that something is either black or the last frame of the previous video played).

我想知道的是,您是否可以从我的logcat得知这是不对的.我对没有标题为ButtonBookActivity的消息感到好奇.他们正常吗?这些是mp4.请注意,在这种情况下,准备视频只需要120毫秒.

What I'm wondering is whether you can tell from my logcat that something is not right with this. I'm curious about the messages that aren't titled ButtonBookActivity. Are they normal? These are mp4s. Note that preparing the video in this case takes only 120ms.

04-15 13:30:05.600: D/ButtonBookActivity(1238): video is reset
04-15 13:30:05.620: I/NuCachedSource2(83): ERROR_END_OF_STREAM
04-15 13:30:05.630: D/AwesomePlayer(83): Failed to open file, all profile flags have to set through setprop method.
04-15 13:30:05.630: I/MPEG4Extractor(83):  NON-QT MODE DECIDED 
04-15 13:30:05.640: I/SampleTable(83): There are reordered frames present.
04-15 13:30:05.640: D/ButtonBookActivity(1238): video is preparing
04-15 13:30:05.640: I/OMXCodec(83): [OMX.Nvidia.h264.decode] AVC profile = 77 (Main), level = 32
04-15 13:30:05.640: I/OMXCodec(83): [OMX.Nvidia.h264.decode] video dimensions are 800 x 1280
04-15 13:30:05.640: I/OMXCodec(83): [OMX.Nvidia.h264.decode] Crop rect is 800 x 1280 @ (0, 0)
04-15 13:30:05.760: D/ButtonBookActivity(1238): video is prepared
04-15 13:30:06.540: D/ButtonBookActivity(1238): touch event
04-15 13:30:06.540: D/ButtonBookActivity(1238): button clicked
04-15 13:30:06.550: D/ButtonBookActivity(1238): calling playmovie in onTouch callback
04-15 13:30:06.550: D/ButtonBookActivity(1238): playing movie
04-15 13:30:06.550: D/ButtonBookActivity(1238): delaying movie reveal
04-15 13:30:06.560: D/NvOsDebugPrintf(83): Allocating new output: 800x1280 (x 12)
04-15 13:30:06.570: I/OMXCodec(83): [OMX.Nvidia.h264.decode] video dimensions are 800 x 1280
04-15 13:30:06.570: I/OMXCodec(83): [OMX.Nvidia.h264.decode] Crop rect is 800 x 1280 @ (0, 0)
04-15 13:30:06.620: D/ButtonBookActivity(1238): touch event
04-15 13:30:06.620: D/ButtonBookActivity(1238): ignoring touch event
04-15 13:30:06.770: V/NvAudioALSA(83): open called for devices 00000002 in mode 0...
04-15 13:30:06.770: V/NvAudioALSA(83): getAlsaDeviceName::devices 0x2 IsVoiceCallDevice 0 devName music
04-15 13:30:06.770: V/NvAudioALSA(83): Reset buffer size to 4096 and latency to 92879
04-15 13:30:06.770: V/NvAudioALSA(83): Set PLAYBACK PCM format to S16_LE (Signed 16 bit Little Endian)
04-15 13:30:06.770: V/NvAudioALSA(83): Using 2 channels for PLAYBACK.
04-15 13:30:06.770: V/NvAudioALSA(83): Set PLAYBACK sample rate to 44100 HZ
04-15 13:30:06.770: V/NvAudioALSA(83): Buffer size: 4096
04-15 13:30:06.770: V/NvAudioALSA(83): Period size: 1024
04-15 13:30:06.770: V/NvAudioALSA(83): Latency: 92879
04-15 13:30:06.770: V/NvAudioALSA(83): Period Time: 23219
04-15 13:30:06.770: V/NvAudioALSA(83): Periods: 4
04-15 13:30:07.060: V/NvAudioALSA(83): Initialized ALSA PLAYBACK device music
04-15 13:30:09.550: D/ButtonBookActivity(1238): video completed

推荐答案

可能与android音频延迟问题有关. 在实际没有声音从扬声器发出之前,对音频文件的start()的调用需要一些时间.也许这也适用于视频,并且媒体播放器需要一些时间才能显示任何视频帧.

This could be related to the android audio latency problem. The call to start() for an audio file needs some time, before there is actually sound coming out of the speakers. Perhaps this also applies to videos and the mediaplayer needs some time before it shows any videoframes.

所以您无能为力.

这篇关于Android MediaPlayer:准备好的视频需要250毫秒才能开始播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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