当我播放视频时,使用 prepareAsync(),然后在视频准备好后调用 start(),从调用 start() 到视频真正开始播放大约需要 250 毫秒。事情就是这样,还是这里发生了什么有趣的事情?请注意,视频位于原始目录中。在我的 Activity 的 OnCreate 中,我有:
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() 一定毫秒数后,我将这张图片拉开并显示视频。在我的设备上,我必须将其设置为 250 毫秒才能可靠地不显示视频以外的内容(该内容要么是黑色的,要么是上一个播放视频的最后一帧)。
我想知道您是否可以从我的 logcat 中看出这有什么不对的地方。我很好奇没有标题为 ButtonBookActivity 的消息。他们正常吗?这些是 mp4。请注意,在这种情况下准备视频只需要 120 毫秒。
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
最佳答案
This可能与android音频延迟问题有关。 在扬声器真正发出声音之前,为音频文件调用 start() 需要一些时间。也许这也适用于视频,媒体播放器需要一些时间才能显示任何视频帧。
所以您可能无能为力。
关于安卓媒体播放器 : prepared video takes 250ms to start playing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10165972/