2

当我播放视频时,使用 prepareAsync(),然后在准备好视频时调用 start(),从 start() 调用到视频实际开始播放大约需要 250 毫秒。是这样吗,还是这里发生了什么有趣的事情?请注意,视频位于原始目录中。在我的活动的 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
4

1 回答 1

1

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

因此,您可能无能为力。

于 2012-07-09T10:32:13.210 回答