android 多媒体编程(四) Vitamio播放视频

爱被打了一巴掌 2022-08-22 05:55 369阅读 0赞

优点:支持格式多 android 自带的仅仅支持3gp mp4

使用和VideoView 基本一致

api:https://www.vitamio.org/docs/API/2013/0508/9.html

1导入包 (可以使用demo里面的 最新的有点问题)

2布局

  1. <io.vov.vitamio.widget.VideoView
  2. android:id="@+id/video"
  3. android:layout_width="wrap_content"
  4. android:layout_height="300dp"/>

3代码:

  1. package cn.zsp.videoview;
  2. import android.app.Activity;
  3. import android.content.res.Configuration;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import io.vov.vitamio.LibsChecker;
  8. public class MainActivity extends Activity {
  9. io.vov.vitamio.widget.VideoView videoView;
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14. if(!LibsChecker.checkVitamioLibs(this)){ return;} //判断硬件是不是支持 是不是安装成功
  15. videoView= (io.vov.vitamio.widget.VideoView ) findViewById(R.id.video);
  16. videoView.setMediaController(new io.vov.vitamio.widget.MediaController(this));//添加控制器
  17. //videoView.setVideoLayout(R.id.video,1);
  18. // videoView.setVideoLayout(3, 1);
  19. try {
  20. videoView= (io.vov.vitamio.widget.VideoView ) findViewById(R.id.video);
  21. Uri uri=Uri.parse("http://49.122.47.217:8080/bfx.mkv");
  22. videoView.setVideoURI(uri);
  23. videoView.start();
  24. } catch (Exception e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. public void onConfigurationChanged(Configuration newConfig) {
  29. super.onConfigurationChanged(newConfig);
  30. //切换为竖屏
  31. if (newConfig.orientation == this.getResources().getConfiguration().ORIENTATION_PORTRAIT) {
  32. //添加自己的业务逻辑
  33. Log.e("zsp", "竖屏: " );
  34. // videoView.setVideoLayout(1, 0);
  35. videoView.setVideoLayout(1,2);
  36. }
  37. //切换为横屏
  38. else if (newConfig.orientation == this.getResources().getConfiguration().ORIENTATION_LANDSCAPE){
  39. //添加自己的业务逻辑
  40. Log.e("zsp", "横屏: " );
  41. videoView.setVideoLayout(2, 1);
  42. }
  43. }
  44. }

清单文件需要加上一个activity sdk 检测用

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="cn.zsp.videoview">
  4. <uses-permission android:name="android.permission.INTERNET"/>
  5. <application
  6. android:allowBackup="true"
  7. android:icon="@mipmap/ic_launcher"
  8. android:label="@string/app_name"
  9. android:supportsRtl="true"
  10. android:theme="@style/AppTheme">
  11. <activity android:name=".MainActivity"
  12. android:configChanges="orientation|keyboardHidden|screenSize">
  13. <intent-filter>
  14. <action android:name="android.intent.action.MAIN"/>
  15. <category android:name="android.intent.category.LAUNCHER"/>
  16. </intent-filter>
  17. </activity>
  18. <activity
  19. android:name="io.vov.vitamio.activity.InitActivity"
  20. android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
  21. android:launchMode="singleTop"
  22. android:theme="@android:style/Theme.NoTitleBar"
  23. android:windowSoftInputMode="stateAlwaysHidden" />
  24. </application>
  25. </manifest>

链接:http://pan.baidu.com/s/1ge5r8sj 密码:jyme

发表评论

表情:
评论列表 (有 0 条评论,369人围观)

还没有评论,来说两句吧...

相关阅读