赞
踩
GitHub 地址
最新版本:2.13.2
ExoPlayer 是运行在 YouTube app Android 版本上的视频播放器。
优点:
#EXT-X-DISCONTINUITY
标签。1. 添加依赖
implementation 'com.google.android.exoplayer:exoplayer:2.11.0'
2. 清单文件中申请权限及 application 设置
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hk.test">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/app_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true" //需加上,避免报错
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
3. 布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
4. MainActivity.java
public class MainActivity extends AppCompatActivity {
private PlayerView mPlayerView;
private SimpleExoPlayer player;
private boolean playWhenReady;
private int currentWindow;
private long playbackPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
mPlayerView = findViewById(R.id.video_view);
initializePlayer();
}
private void initializePlayer() {
player = new SimpleExoPlayer.Builder(this).build();
player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow, playbackPosition);
Uri playUri = Uri.parse("https://stream7.iqilu.com/10339/upload_transcode/202002/18/20200218114723HDu3hhxqIT.mp4");
MediaSource mediaSource = buildMediaSource(playUri);
player.prepare(mediaSource, true, false);
mPlayerView.setPlayer(player);
}
private MediaSource buildMediaSource(Uri uri) {
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, "com.example.exoplayerdemo");
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
return videoSource;
}
@Override
protected void onDestroy() {
super.onDestroy();
player.release();
}
}
新冠肺炎疫情相关视频:武汉加油中国加油
20 条速度比较快的地址:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。