1)videoView播放视频
//布局文件
public class MainActivity extends Activity {
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取控件
videoView = (VideoView) findViewById(R.id.videoView);
//获取路径
videoView.setVideoPath("mnt/sdcard/minion_08.mp4");
//实例化媒体控件
MediaController controller = new MediaController(this);
//设置媒体控件
videoView.setMediaController(controller);
//绑定view
controller.setAnchorView(videoView);
//播放
videoView.start();
}
}
//MainActivity网络
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView vv=(VideoView) findViewById(R.id.vv);
Uri uri = Uri.parse("视频路径");
vv.setMediaController(new MediaController(this));
vv.setVideoURI(uri);
vv.start();
}
}
导入依赖,minSdkVersion最低为16以上
compile 'fm.jiecao:jiecaovideoplayer:5.5'
>
public class MainActivity extends AppCompatActivity {
private JCVideoPlayerStandard jcVideoPlayerStandard;
//测试地址
String s1 = "https://txmov2.a.yximgs.com/upic/2017/06/22/23/BMjAxNzA2MjIyMzEyMThfNzAyMzQ4Ml8yNDU3OTA1MjA1XzJfMw==_b.mp4";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//设置标题 有需要的可以试一下
//getSupportActionBar().setTitle("jiecaovideoplayer的使用");
//找控件
jcVideoPlayerStandard = (JCVideoPlayerStandard) findViewById(R.id.jiecao_Player);
//设置视频上显示的文字
jcVideoPlayerStandard.setUp(s1, JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "妖王现世");
}
/**
* 不要忘了这两个方法
*/
@Override
public void onBackPressed() {
if (JCVideoPlayer.backPress()) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
JCVideoPlayer.releaseAllVideos();
}
}
//方式一
依赖
compile 'com.github.leifzhang:IjkLib:0.4.3'
MainActivity
public class MainActivity extends AppCompatActivity {
private IjkVideoView ijkPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
ijkPlayer = (IjkVideoView)findViewById(R.id.ijkPlayer);
AndroidMediaController controller = new AndroidMediaController(this, false);
ijkPlayer.setMediaController(controller);
String url = "http://movie.vods1.cnlive.com/3/vod/2017/0607/3_5d21bed962f44c8eac068942745187ef/ff8080815bf6b453015c83457e311a95_1500.m3u8";
ijkPlayer.setVideoURI(Uri.parse(url));
ijkPlayer.start();
}
}
compile 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5'
布局文件
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*View rootView = getLayoutInflater().from(this).inflate(R.layout.simple_player_view_player, null);
setContentView(rootView);*/
new PlayerView(this)
.setTitle("什么")
.setScaleType(PlayStateParams.fitparent)
.hideMenu(true)
.forbidTouch(false)
.setPlaySource("http://movie.vods1.cnlive.com/3/vod/2017/0607/3_5d21bed962f44c8eac068942745187ef/ff8080815bf6b453015c83457e311a95_1500.m3u8")
.startPlay();
}
}