ijkPlayer 实现视频播放
程序员文章站
2024-01-16 19:15:10
...
首先导入依赖
compile 'com.github.open-android:IjkPlayer:1.0.0'
implementation 'com.facebook.fresco:fresco:0.13.0'
implementation 'com.facebook.fresco:animated-gif:0.13.0'
compile 'io.reactivex.rxjava2:rxjava:2.1.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
以及网路权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
一个简单的视图
<com.dl7.player.media.IjkPlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="300dp">
</com.dl7.player.media.IjkPlayerView>
<com.facebook.drawee.view.SimpleDraweeView
android:layout_marginTop="30dp"
android:id="@+id/sdv"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp" />
//Mainactivity
public class MainActivity extends AppCompatActivity {
private IjkPlayerView mPlayerView;
private SimpleDraweeView sdv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fresco.initialize(this);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
mPlayerView = (IjkPlayerView) findViewById(R.id.player_view);
sdv = (SimpleDraweeView) findViewById(R.id.sdv);
Uri mUri = Uri.parse("http://ips.ifeng.com/video19.ifeng.com/video09/2014/06/16/1989823-102-086-0009.mp4");
mPlayerView.init()
.setVideoPath(mUri)
.setMediaQuality(IjkPlayerView.MEDIA_QUALITY_SMOOTH)
.enableDanmaku()
.start();
initView();
sdv.setImageURI("http://pic.58pic.com/58pic/13/17/54/40J58PICyAY_1024.jpg");
}
@Override
protected void onResume() {
super.onResume();
mPlayerView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mPlayerView.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
mPlayerView.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mPlayerView.configurationChanged(newConfig);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (mPlayerView.handleVolumeKey(keyCode)) {
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
if (mPlayerView.onBackPressed()) {
return;
}
super.onBackPressed();
}
private void initView() {
}
}
Ok把这些贴完就能玩成bw项目二最后一天的日考了!