Android 简单IjkVideoView播放视频

ijkplayer是Bilibili基于ffmpeg开发并开源的轻量级视频播放器,支持播放本地网络视频,也支持流媒体播放。支持Android&iOS。

效果展示

这里写图片描述

导包

ijkplayer导包源码下载https://github.com/lmx-fashion/IjikPlayer
我们需要的只有widget.media和libs

然后进行配置就好了

修改APP下的build.gradle, 主要设置.so及.aar的位置:

    apply plugin: 'com.android.application'  

    android {  
        compileSdkVersion 24  
        buildToolsVersion "25.0.0"  
        defaultConfig {  
            applicationId "com.hx.ijkplayer_demo"  
            minSdkVersion 14  
            targetSdkVersion 24  
            versionCode 1  
            versionName "1.0"  
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"  
        }  
        buildTypes {  
            release {  
                minifyEnabled false  
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'  
            }  
        }  
        sourceSets {  
            main {  
                jniLibs.srcDirs = ['libs']  /**在libs文件夹下找so文件*/  
            }  
        }  
    }  

    repositories {  
        mavenCentral()  
        flatDir {  
            dirs 'libs' /**在libs文件夹下找aar文件*/  
        }  
    }  

    dependencies {  
        compile fileTree(dir: 'libs', include: ['*.jar'])  
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {  
            exclude group: 'com.android.support', module: 'support-annotations'  
        })  
        compile 'com.android.support:appcompat-v7:24.2.1'  
        testCompile 'junit:junit:4.12'  
        compile(name: 'ijkplayer-java-release', ext: 'aar') /**编译ijkplayer-java-release.aar文件*/  
    }  
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

第二步就是清单文件

    <uses-permission android:name="android.permission.INTERNET"/>  
       <application  
           android:configChanges="orientation|keyboardHidden"     《》------ //手机二次退出  
           android:allowBackup="true"  
           android:icon="@mipmap/ic_launcher"  
           android:label="@string/app_name"  
           android:supportsRtl="true"  
           android:theme="@style/AppTheme">  
           <activity android:name=".MainActivity"  
               android:screenOrientation="sensorLandscape"-------------这两行配置  
               android:configChanges="orientation|keyboardHidden">  
               <intent-filter>  
                   <action android:name="android.intent.action.MAIN" />  

                   <category android:name="android.intent.category.LAUNCHER" />  
               </intent-filter>  
           </activity>  
       </application>  
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

Xml代码,其中的IjkVideoView的路径需要自己根据自己studio的提示配置,

    <?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:id="@+id/activity_main"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:paddingBottom="@dimen/activity_vertical_margin"  
        android:paddingLeft="@dimen/activity_horizontal_margin"  
        android:paddingRight="@dimen/activity_horizontal_margin"  
        android:paddingTop="@dimen/activity_vertical_margin"  
        tools:context="com.eightgroup.ijkplayer.MainActivity">  

        <com.eightgroup.ijkplayer.widget.media.IjkVideoView  
            android:id="@+id/video_view"  
            android:layout_width="match_parent"  
            android:layout_height="match_parent"/>  
    </RelativeLayout>  
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

MainActivity

    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://mp4.vjshi.com/2013-05-28/2013052815051372.mp4"));  
            videoView.start();  
        }  
    }  
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

导入工具类widget.media

这里写图片描述

导入lib包

这里写图片描述

            <link rel="stylesheet" href="http://s.csdnimg.cn/static/production/markdown_views-d4dade9c33.css">
                </div>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值