4.集成Vitamio
4.1,拷贝权限到项目中来
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
4.2 拷贝InitActivity的,在功能清单文件配置,代码如下:
<!-- Don't forgot InitActivity -->
<activity
android:name="io.vov.vitamio.activity.InitActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden" />
4.3,新创建一个Activity名字叫VitamioVideoPlayerActivity
重新创建布局文件activity_vitamio_videoplayer.xml,把布局文件里面的系统的VideoView换成Vitamio的VideoView,导入的包都要换成是Vitamio的
<io.vov.vitamio.widget.VideoView
android:id="@+id/surface_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
4.4.需要把VitamioVideoPlayerActivity在功能清单文件里面注册
<activity android:name=".VitamioVideoPlayerActivity"
android:configChanges="keyboardHidden|screenSize|orientation"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
/>
4.5,要在加载布局文件之前,初始化解码器
Vitamio.isInitialized(this);
4.6,当系统播放器出错的时候,记得跳转到Vitmaio播放中,并且不要忘记携带数据
/**
* 启动Vitamio解码播放器
* a,把数据按照原样传入VtaimoVideoPlayer播放器
* b,关闭系统播放器
*/
private void startVitamioPlayer()
{
if(videoview!=null)
{
videoview.stopPlayback();
}
Intent intent = new Intent(this, VitamioVideoPlayer.class);
if(mediaItems!=null && mediaItems.size()>0)
{
Bundle bundle = new Bundle();
bundle.putSerializable("videolist",mediaItems);
intent.putExtras(bundle);
intent.putExtra("position",position);
}
else if(uri!=null)
{
intent.setData(uri);
}
startActivity(intent);
finish();//关闭页面
} |