Android——视频播放框架ijkplayer的简单使用

首先导入依赖包:compile 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5'

如果不是全屏播放添加如下布局

xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.hx.ijkplayer_demo.widget.media.IjkVideoView
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="高度自己定"/>
RelativeLayout>

java代码:

public class MainActivity extends AppCompatActivity {

    private IjkVideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        videoView = (IjkVideoView) findViewById(R.id.video_view);
        videoView.setAspectRatio(IRenderView.AR_ASPECT_FIT_PARENT);
        videoView.setVideoURI(Uri.parse("http://zv.3gv.ifeng.com/live/zhongwen800k.m3u8"));
        videoView.start();
    }
}

如果是全屏播放则不用写布局直接看Java代码:

public class VideoActivity extends AppCompatActivity {
    PlayerView playerView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);

        View rootView = getLayoutInflater().from(this).inflate(R.layout.simple_player_view_player, null);
        setContentView(rootView);
       

        playerView = new PlayerView(this)
                .setScaleType(PlayStateParams.fitparent)
                .setPlaySource(url)
                .setTitle("标题")
                .startPlay();

    }

}

 
  
 
  







你可能感兴趣的:(Android——视频播放框架ijkplayer的简单使用)