Android 简单IjkVideoView视频播放

来源:互联网 发布:去马赛克软件下载 编辑:程序博客网 时间:2024/05/29 19:23

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文件*/      }  

第二步就是清单文件

    <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>  

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>  

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();          }      }  

导入工具类widget.media

这里写图片描述

导入lib包

这里写图片描述

原创粉丝点击