【发布时间】:2016-02-24 12:25:28
【问题描述】:
我目前使用 exoplayer 只是通过执行以下设置在表面视图 (http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_50mb.mp4) 上播放示例视频:
player = (SurfaceView)rootView.findViewById(R.id.player_surface_view);
Allocator a = new DefaultAllocator(1);
DataSource ds = new DefaultUriDataSource(getActivity(),"a");
SampleSource sampleSource = new ExtractorSampleSource(Uri.parse("http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_50mb.mp4"), ds, a,1,null);
MediaCodecSelector mcs = MediaCodecSelector.DEFAULT;
//VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING or VIDEO_SCALING_MODE_SCALE_TO_FIT
TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(getActivity(),sampleSource,mcs, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,mcs);
exoPlayer = ExoPlayer.Factory.newInstance(2,10000,50000);
exoPlayer.prepare(videoRenderer, audioRenderer);
exoPlayer.addListener(this);
exoPlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, player.getHolder().getSurface());
exoPlayer.setPlayWhenReady(true);
在监听器上我正在记录 exoplayerstate:
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
Log.i("exoplayerstate","onPlayerStateChanged"+" "+playWhenReady+ " "+playbackState);
}
结果:
exoplayerstate: onPlayerStateChanged true 1
exoplayerstate: onPlayerStateChanged true 2
exoplayerstate: onPlayerStateChanged true 3
exoplayerstate: onPlayerStateChanged true 3
通过查看 exoplayer 文档,状态代码为:
STATE_IDLE = 1;状态准备 = 2;状态缓冲= 3;状态就绪 = 4; STATE_ENDED = 5;
顺便说一句,我不认为是相关的,但是,我的视图 xml 是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer.AspectRatioFrameLayout
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<SurfaceView
android:id="@+id/player_surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</com.google.android.exoplayer.AspectRatioFrameLayout>
谁能告诉我为什么我从来没有达到 state = 4 (STATE_READY) 以便视频可以开始播放?
【问题讨论】:
-
请看这个答案,看看它是否对你有帮助:stackoverflow.com/questions/26902670/…
-
没有!还是谢谢
-
您找到解决方案了吗?我也有同样的问题。请帮忙!
标签: android video-streaming surfaceview android-video-player exoplayer