ExoPlayer 不播放视频
ExoPlayer doesn't play video
我已经完成了用于播放 HLS 的 ExoPlayer 的下一个实现:
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 实现指南:
https://exoplayer.dev/hello-world.html
看来我做对了一切。
有人知道为什么它不起作用吗?
在 Activity 中实现,而不是在适配器 class 中实现。
我已经完成了用于播放 HLS 的 ExoPlayer 的下一个实现:
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 实现指南: https://exoplayer.dev/hello-world.html
看来我做对了一切。
有人知道为什么它不起作用吗?
在 Activity 中实现,而不是在适配器 class 中实现。