Android ExoPlayer不';我不能播放视频
我已经为玩HLS完成了ExoPlayer的下一个实现:Android ExoPlayer不';我不能播放视频,android,user-interface,exoplayer,Android,User Interface,Exoplayer,我已经为玩HLS完成了ExoPlayer的下一个实现: SimpleExoPlayer player; player = ExoPlayerFactory.newSimpleInstance(mContext, trackSelector, loadControl); Handler mHandler = new Handler(); String userAgent = Util.getUserAgent(mC
SimpleExoPlayer player;
player = ExoPlayerFactory.newSimpleInstance(mContext, trackSelector, loadControl);
Handler mHandler = new Handler();
String userAgent = Util.getUserAgent(mContext, "appName");
DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
userAgent, null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
1800000,
true);
HlsMediaSource mediaSource = new HlsMediaSource(Uri.parse(URL), dataSourceFactory, 1800000,
mHandler, null);
player.setPlayWhenReady(true);
player.prepare(mediaSource);
然后我发现我的代码只播放音频,我一直在搜索,直到我发现:
PlayerView playerView;
playerView = view.findViewById(R.id.pView);
playerView.setPlayer(player);
使用playerView进行布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RLteleNew"
android:keepScreenOn="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray21"
>
...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/LLtopnew2"
>
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/pView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:visibility="visible">
</com.google.android.exoplayer2.ui.PlayerView>
</RelativeLayout>
</RelativeLayout>
...
在所有示例中,这都是播放视频的解决方案,但当我将其添加到代码中时,Exoplayer什么也不播放
我应该在代码中编辑什么
找到了一个关于ExoPlayer实施的好指南:
看来我做的每件事都是对的
有人知道它为什么不工作吗?在活动中实现它,而不是在适配器类中