前言
做一款视频播放器需要多久?有了ijkplayer只需要简单几步就能快速搞出来一个功能强大播放器。
github链接:ijkplayer
Android:
Gradle
required
allprojects {
repositories {
jcenter()
}
}
dependencies {
# required, enough for most devices.
compile 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'
# Other ABIs: optional
compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.8.8'
compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8'
compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8'
compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8'
# ExoPlayer as IMediaPlayer: optional, experimental
compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.8.8'
}
上面是android studio 快速依赖项。
我自己项目下载0.8.8 so下载不下来。改用其他依赖方式,如何也遇到无法下载下载依赖问题可以试试下面的依赖:
api 'com.github.open-android:IjkPlayer:1.0.0'
api 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
1.xml文件:
定义播放 Ijkplayerview,视频播放主界面。大小随意调整
2.kotlin 代码
player_view.init()
.setVideoPath(mUri)
.setMediaQuality(IjkPlayerView.DRAWING_CACHE_QUALITY_AUTO)
.setTitle("0000")
.start()
tips:
初始化view,设置资源url,设置视频画面的质量(这里设置为根据网络自动进行调整),设置全屏时候的标题。start( )开始缓冲视频,完成自动播放
手动编译so库,如果需要支持https协议手动进行设置
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android
cd ijkplayer-android
git checkout -B latest k0.8.8
./init-android.sh
cd android/contrib
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
cd ..
./compile-ijk.sh all
# Android Studio:
# Open an existing Android Studio project
# Select android/ijkplayer/ and import
#
# define ext block in your root build.gradle
# ext {
# compileSdkVersion = 23 // depending on your sdk version
# buildToolsVersion = "23.0.0" // depending on your build tools version
#
# targetSdkVersion = 23 // depending on your sdk version
# }
#
# If you want to enable debugging ijkplayer(native modules) on Android Studio 2.2+: (experimental)
# sh android/patch-debugging-with-lldb.sh armv7a
# Install Android Studio 2.2(+)
# Preference -> Android SDK -> SDK Tools
# Select (LLDB, NDK, Android SDK Build-tools,Cmake) and install
# Open an existing Android Studio project
# Select android/ijkplayer
# Sync Project with Gradle Files
# Run -> Edit Configurations -> Debugger -> Symbol Directories
# Add "ijkplayer-armv7a/.externalNativeBuild/ndkBuild/release/obj/local/armeabi-v7a" to Symbol Directories
# Run -> Debug 'ijkplayer-example'
# if you want to reverse patches:
# sh patch-debugging-with-lldb.sh reverse armv7a
#
# Eclipse: (obselete)
# File -> New -> Project -> Android Project from Existing Code
# Select android/ and import all project
# Import appcompat-v7
# Import preference-v7
#
# Gradle
# cd ijkplayer
# gradle
tips: 手动编译so库,需要下载NDK 库,博主下载了最新的ndk库文件,编译时候报异常,提示需要指定版本的ndk,项目紧,网上找到了网友编译好的so库。
支持https,ndk库 下载
so库比较大,这里我的项目中只使用了armeabi,和X86两种so
builde.gradle中对ndk进行过滤
android {
...
...
...
ndk {
abiFilter "armeabi"
abiFilter "x86"
}
}