首先导入依赖包:
compile 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5'
如果全屏播放就不用粘贴布局了;如果是屏幕中一小块的话就粘贴这个布局:
<include
layout="@layout/simple_player_view_player"
android:layout_width="match_parent"
android:layout_height="180dp"/>
然后是代码粘贴到MainActivity的onCreat中就可以:
/*View rootView = getLayoutInflater().from(this).inflate(R.layout.simple_player_view_player, null);
setContentView(rootView);*/全屏时添加这句
String url = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/local2/adc.mp4";
newPlayerView(this)
.setTitle("什么")
.setScaleType(PlayStateParams.fitparent)
.hideMenu(true)
.forbidTouch(false)
.setPlaySource(url)
.startPlay();
注释部分如果你要全屏播放就打开要不是的话就注释掉,我播放的是本地视频,这个也可以播放网络视频,只要把url改好把权限加上(网络,读写,网络状态)就行;
在fragment中的使用
package com.bwie.ijkplayer; import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.dou361.ijkplayer.widget.PlayStateParams; import com.dou361.ijkplayer.widget.PlayerView; /** * Created by T_baby on 17/12/01. */ public class frg extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { new PlayerView((Activity) getContext()) .setTitle("什么") .setScaleType(PlayStateParams.fitparent) .hideMenu(true) .forbidTouch(false) .setPlaySource("http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4") .startPlay(); return LayoutInflater.from(getContext()).inflate(R.layout.layout,null,false); } }