Android ijkplayer详解使用教程
1.认识ijkplayer
最近公司准备开发一款视频播放及直播的应用,找了许多开源的框架,大部分都是基于ffmpeg开发的。最开始准备用Vitamio框架开发的,相关的文章也比较丰富,结果对于非个人移动应用均需购买Vitamio使用授权。不过B站开源的ijkplayer也不错,而且也不需要商业授权。
ijkplayer是一个基于FFmpeg的轻量级Android/iOS视频播放器。FFmpeg的是全球领先的多媒体框架,能够解码,编码, 转码,复用,解复用,流,过滤器和播放大部分的视频格式。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开发的。
2.环境配置
项目中引入ijkplayer环境有两种方式。
2.1在Gradle中引入
# required
allprojects {
repositories {
jcenter()
}
}
dependencies {
# required, enough for most devices.
compile 'tv.danmaku.ijk.media:ijkplayer-java:0.6.1'
compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.6.1'
# Other ABIs: optional
compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.6.1'
compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.6.1'
compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.6.1'
compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.6.1'
# ExoPlayer as IMediaPlayer: optional, experimental
compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.6.1'
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
2.2在Ubuntu下编译源码得到
Ubuntu需要安装homebrew, Git, yasm
# install homebrew, git, yasm
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
brew install yasm
# add these lines to your ~/.bash_profile or ~/.profile
# export ANDROID_SDK=<your sdk path>
# export ANDROID_NDK=<your ndk path>
# on Cygwin (unmaintained)
# install git, make, yasm
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
开始编译
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android
cd ijkplayer-android
git checkout -B latest k0.6.1
./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
# }
#
# 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
- 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
- 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
目录结构
3.播放器使用
可能是网络的问题,使用Gradle导入会花费很长时间,如果遇到超时,还得重头来一遍,太费时间了。后来我就直接在Ubuntu下编译后,在android Studio下导入该项目。我先介绍下Demo中利用ijkplayer播放视频的过程。
3.1初始化播放器
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
- 1
- 2
- 1
- 2
3.2初始化IjkVideoView
//这里使用的是Demo中提供的AndroidMediaController类控制播放相关操作
mMediaController = new AndroidMediaController(this, false);
mMediaController.setSupportActionBar(actionBar);
mVideoView = (IjkVideoView) findViewById(R.id.video_view);
mVideoView.setMediaController(mMediaController);
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
3.3设置本地视频文件位置或服务器地址,然后播放
mVideoView.setVideoPath(mVideoPath);
mVideoView.start();
- 1
- 2
- 1
- 2
3.4Activity销毁时,需要释放资源
@Override
public void onBackPressed() {
mBackPressed = true;
super.onBackPressed();
}
@Override
protected void onStop() {
super.onStop();
//点击返回或不允许后台播放时 释放资源
if (mBackPressed || !mVideoView.isBackgroundPlayEnabled()) {
mVideoView.stopPlayback();
mVideoView.release(true);
mVideoView.stopBackgroundPlay();
} else {
mVideoView.enterBackground();
}
IjkMediaPlayer.native_profileEnd();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
4.自定义播放器
当然官方提供的Demo只是演示视频播放的基本操作,对于视频播放的控制、全屏等操作,还要自己动手做。
4.1部分声明
private static final int SIZE_DEFAULT = 0;
private static final int SIZE_4_3 = 1;
private static final int SIZE_16_9 = 2;
private int currentSize = SIZE_16_9;
private IjkVideoView video;
private SeekBar seekBar;
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
4.2视频播放比例
这里需要修改IjkVideoView部分代码后,才支持按比例播放
//修改相关代码
private static final int[] s_allAspectRatio = {
IRenderView.AR_ASPECT_FIT_PARENT,
IRenderView.AR_ASPECT_FILL_PARENT,
IRenderView.AR_ASPECT_WRAP_CONTENT,
IRenderView.AR_MATCH_PARENT,
IRenderView.AR_16_9_FIT_PARENT,
IRenderView.AR_4_3_FIT_PARENT
};
private int mCurrentAspectRatioIndex = 3;//0
private int mCurrentAspectRatio = s_allAspectRatio[3];//0
private int mCurrentRender = RENDER_TEXTURE_VIEW;
//增加下面方法
public IRenderView getmRenderView() {
return mRenderView;
}
public int getmVideoWidth() {
return mVideoWidth;
}
public int getmVideoHeight() {
return mVideoHeight;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
设置视频播放比例
public void setScreenRate(int rate) {
int width = 0;
int height = 0;
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {// 横屏
if (rate == SIZE_DEFAULT) {
width = video.getmVideoWidth();
height = video.getmVideoHeight();
} else if (rate == SIZE_4_3) {
width = screenHeight / 3 * 4;
height = screenHeight;
} else if (rate == SIZE_16_9) {
width = screenHeight / 9 * 16;
height = screenHeight;
}
} else { //竖屏
if (rate == SIZE_DEFAULT) {
width = video.getmVideoWidth();
height = video.getmVideoHeight();
} else if (rate == SIZE_4_3) {
width = screenWidth;
height = screenWidth * 3 / 4;
} else if (rate == SIZE_16_9) {
width = screenWidth;
height = screenWidth * 9 / 16;
}
}
if (width > 0 && height > 0) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) video.getmRenderView().getView().getLayoutParams();
lp.width = width;
lp.height = height;
video.getmRenderView().getView().setLayoutParams(lp);
}
}
- 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
- 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
4.3屏幕方向切换
private void fullChangeScreen() {
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {// 切换为竖屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
4.4全屏播放
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//重新获取屏幕宽高
initScreenInfo();
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {//切换为横屏
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) video.getLayoutParams();
lp.height = screenHeight;
lp.width = screenWidth;
video.setLayoutParams(lp);
} else {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) video.getLayoutParams();
lp.height = screenWidth * 9 / 16;
lp.width = screenWidth;
video.setLayoutParams(lp);
}
setScreenRate(currentSize);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
4.5播放进度
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
....
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
video.seekTo(seekBar.getProgress()*video.getDuration()/100);
...
}
});
//视频开始播放时使用handle.sendMessageDelayed更新时间显示
private void refreshTime(){
int totalSeconds = video.getCurrentPosition() / 1000;
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
String ti=hours > 0 ? String.format("%02d:%02d:%02d", hours, minutes, seconds):String.format("%02d:%02d", minutes, seconds);
time.setText(ti);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
5.相关资料
- 官网地址:https://github.com/Bilibili/ijkplayer
- 已编译好的环境:http://download.csdn.net/detail/u010987039/9611675
- 测试用服务器地址:
http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8(可用)
http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8
http://playertest.longtailvideo.com/adaptive/oceans_aes/oceans_aes.m3u8 (AES encrypted)
http://playertest.longtailvideo.com/adaptive/captions/playlist.m3u8 (HLS stream with CEA-608 captions)
http://playertest.longtailvideo.com/adaptive/wowzaid3/playlist.m3u8 (with metadata)
http://content.jwplatform.com/manifests/vM7nH0Kl.m3u8
http://cdn-fms.rbs.com.br/hls-vod/sample1_1500kbps.f4v.m3u8
http://cdn-fms.rbs.com.br/vod/hls_sample1_manifest.m3u8(可用)
http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch1/appleman.m3u8 (LIVE TV可用)
http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch2/appleman.m3u8 (LIVE TV)
http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch3/appleman.m3u8 (LIVE TV)
https://dl.dropboxusercontent.com/u/7303267/website/m3u8/index.m3u8 (VOD) - [updated]
http://content.jwplatform.com/manifests/vM7nH0Kl.m3u8 (link protection, video not encrypted)
http://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8 (4K)
http://cdn3.viblast.com/streams/hls/airshow/playlist.m3u8 (4K)
6.2017-03-31更新
方便大家使用,提供编译好的各平台so文件,再引入“ijkplayer-Java”就可以直接使用。
http://download.csdn.net/detail/u010987039/9800324
1.认识ijkplayer
最近公司准备开发一款视频播放及直播的应用,找了许多开源的框架,大部分都是基于ffmpeg开发的。最开始准备用Vitamio框架开发的,相关的文章也比较丰富,结果对于非个人移动应用均需购买Vitamio使用授权。不过B站开源的ijkplayer也不错,而且也不需要商业授权。
ijkplayer是一个基于FFmpeg的轻量级Android/iOS视频播放器。FFmpeg的是全球领先的多媒体框架,能够解码,编码, 转码,复用,解复用,流,过滤器和播放大部分的视频格式。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开发的。
2.环境配置
项目中引入ijkplayer环境有两种方式。
2.1在Gradle中引入
# required
allprojects {
repositories {
jcenter()
}
}
dependencies {
# required, enough for most devices.
compile 'tv.danmaku.ijk.media:ijkplayer-java:0.6.1'
compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.6.1'
# Other ABIs: optional
compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.6.1'
compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.6.1'
compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.6.1'
compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.6.1'
# ExoPlayer as IMediaPlayer: optional, experimental
compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.6.1'
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
2.2在Ubuntu下编译源码得到
Ubuntu需要安装homebrew, Git, yasm
# install homebrew, git, yasm
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
brew install yasm
# add these lines to your ~/.bash_profile or ~/.profile
# export ANDROID_SDK=<your sdk path>
# export ANDROID_NDK=<your ndk path>
# on Cygwin (unmaintained)
# install git, make, yasm
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
开始编译
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android
cd ijkplayer-android
git checkout -B latest k0.6.1
./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
# }
#
# 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
- 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
- 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
目录结构
3.播放器使用
可能是网络的问题,使用Gradle导入会花费很长时间,如果遇到超时,还得重头来一遍,太费时间了。后来我就直接在Ubuntu下编译后,在android Studio下导入该项目。我先介绍下Demo中利用ijkplayer播放视频的过程。
3.1初始化播放器
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
- 1
- 2
- 1
- 2
3.2初始化IjkVideoView
//这里使用的是Demo中提供的AndroidMediaController类控制播放相关操作
mMediaController = new AndroidMediaController(this, false);
mMediaController.setSupportActionBar(actionBar);
mVideoView = (IjkVideoView) findViewById(R.id.video_view);
mVideoView.setMediaController(mMediaController);
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
3.3设置本地视频文件位置或服务器地址,然后播放
mVideoView.setVideoPath(mVideoPath);
mVideoView.start();
- 1
- 2
- 1
- 2
3.4Activity销毁时,需要释放资源
@Override
public void onBackPressed() {
mBackPressed = true;
super.onBackPressed();
}
@Override
protected void onStop() {
super.onStop();
//点击返回或不允许后台播放时 释放资源
if (mBackPressed || !mVideoView.isBackgroundPlayEnabled()) {
mVideoView.stopPlayback();
mVideoView.release(true);
mVideoView.stopBackgroundPlay();
} else {
mVideoView.enterBackground();
}
IjkMediaPlayer.native_profileEnd();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
4.自定义播放器
当然官方提供的Demo只是演示视频播放的基本操作,对于视频播放的控制、全屏等操作,还要自己动手做。
4.1部分声明
private static final int SIZE_DEFAULT = 0;
private static final int SIZE_4_3 = 1;
private static final int SIZE_16_9 = 2;
private int currentSize = SIZE_16_9;
private IjkVideoView video;
private SeekBar seekBar;
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
4.2视频播放比例
这里需要修改IjkVideoView部分代码后,才支持按比例播放
//修改相关代码
private static final int[] s_allAspectRatio = {
IRenderView.AR_ASPECT_FIT_PARENT,
IRenderView.AR_ASPECT_FILL_PARENT,
IRenderView.AR_ASPECT_WRAP_CONTENT,
IRenderView.AR_MATCH_PARENT,
IRenderView.AR_16_9_FIT_PARENT,
IRenderView.AR_4_3_FIT_PARENT
};
private int mCurrentAspectRatioIndex = 3;//0
private int mCurrentAspectRatio = s_allAspectRatio[3];//0
private int mCurrentRender = RENDER_TEXTURE_VIEW;
//增加下面方法
public IRenderView getmRenderView() {
return mRenderView;
}
public int getmVideoWidth() {
return mVideoWidth;
}
public int getmVideoHeight() {
return mVideoHeight;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
设置视频播放比例
public void setScreenRate(int rate) {
int width = 0;
int height = 0;
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {// 横屏
if (rate == SIZE_DEFAULT) {
width = video.getmVideoWidth();
height = video.getmVideoHeight();
} else if (rate == SIZE_4_3) {
width = screenHeight / 3 * 4;
height = screenHeight;
} else if (rate == SIZE_16_9) {
width = screenHeight / 9 * 16;
height = screenHeight;
}
} else { //竖屏
if (rate == SIZE_DEFAULT) {
width = video.getmVideoWidth();
height = video.getmVideoHeight();
} else if (rate == SIZE_4_3) {
width = screenWidth;
height = screenWidth * 3 / 4;
} else if (rate == SIZE_16_9) {
width = screenWidth;
height = screenWidth * 9 / 16;
}
}
if (width > 0 && height > 0) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) video.getmRenderView().getView().getLayoutParams();
lp.width = width;
lp.height = height;
video.getmRenderView().getView().setLayoutParams(lp);
}
}
- 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
- 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
4.3屏幕方向切换
private void fullChangeScreen() {
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {// 切换为竖屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
4.4全屏播放
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//重新获取屏幕宽高
initScreenInfo();
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {//切换为横屏
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) video.getLayoutParams();
lp.height = screenHeight;
lp.width = screenWidth;
video.setLayoutParams(lp);
} else {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) video.getLayoutParams();
lp.height = screenWidth * 9 / 16;
lp.width = screenWidth;
video.setLayoutParams(lp);
}
setScreenRate(currentSize);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
4.5播放进度
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
....
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
video.seekTo(seekBar.getProgress()*video.getDuration()/100);
...
}
});
//视频开始播放时使用handle.sendMessageDelayed更新时间显示
private void refreshTime(){
int totalSeconds = video.getCurrentPosition() / 1000;
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
String ti=hours > 0 ? String.format("%02d:%02d:%02d", hours, minutes, seconds):String.format("%02d:%02d", minutes, seconds);
time.setText(ti);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
5.相关资料
- 官网地址:https://github.com/Bilibili/ijkplayer
- 已编译好的环境:http://download.csdn.net/detail/u010987039/9611675
- 测试用服务器地址:
http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8(可用)
http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8
http://playertest.longtailvideo.com/adaptive/oceans_aes/oceans_aes.m3u8 (AES encrypted)
http://playertest.longtailvideo.com/adaptive/captions/playlist.m3u8 (HLS stream with CEA-608 captions)
http://playertest.longtailvideo.com/adaptive/wowzaid3/playlist.m3u8 (with metadata)
http://content.jwplatform.com/manifests/vM7nH0Kl.m3u8
http://cdn-fms.rbs.com.br/hls-vod/sample1_1500kbps.f4v.m3u8
http://cdn-fms.rbs.com.br/vod/hls_sample1_manifest.m3u8(可用)
http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch1/appleman.m3u8 (LIVE TV可用)
http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch2/appleman.m3u8 (LIVE TV)
http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch3/appleman.m3u8 (LIVE TV)
https://dl.dropboxusercontent.com/u/7303267/website/m3u8/index.m3u8 (VOD) - [updated]
http://content.jwplatform.com/manifests/vM7nH0Kl.m3u8 (link protection, video not encrypted)
http://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8 (4K)
http://cdn3.viblast.com/streams/hls/airshow/playlist.m3u8 (4K)
6.2017-03-31更新
方便大家使用,提供编译好的各平台so文件,再引入“ijkplayer-Java”就可以直接使用。
http://download.csdn.net/detail/u010987039/9800324
Android ijkplayer详解使用教程的更多相关文章
- Android Notification 详解(一)——基本操作
Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...
- Android Notification 详解——基本操作
Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...
- loadrunner11.0 安装破解详解使用教程
loadrunner11.0 安装破解详解使用教程 来源:互联网 作者:佚名 时间:01-21 10:25:34 [大 中 小] 很多朋友下载了loadrunner11但不是很会使用,这里简单介绍下安 ...
- Android ActionBar详解
Android ActionBar详解 分类: Android2014-04-30 15:23 1094人阅读 评论(0) 收藏 举报 androidActionBar 目录(?)[+] 第4 ...
- Android 签名详解
Android 签名详解 AndroidOPhoneAnt设计模式Eclipse 在Android 系统中,所有安装 到 系统的应用程序都必有一个数字证书,此数字证书用于标识应用程序的作者和在应用程 ...
- Android编译系统详解(一)
++++++++++++++++++++++++++++++++++++++++++ 本文系本站原创,欢迎转载! 转载请注明出处: http://blog.csdn.net/mr_raptor/art ...
- Android布局详解之一:FrameLayout
原创文章,如有转载,请注明出处:http://blog.csdn.net/yihui823/article/details/6702273 FrameLayout是最简单的布局了.所有放在布局里的 ...
- 【整理修订】Android.mk详解
Android.mk详解 1. Android.mk 的应用范围 Android.mk文件是GNU Makefile的一小部分,它用来对Android程序进行编译. 一个Android.mk文件可以编 ...
- Android菜单详解(四)——使用上下文菜单ContextMenu
之前在<Android菜单详解(二)——创建并响应选项菜单>和<Android菜单详解(三)——SubMenu和IconMenu>中详细讲解了选项菜单,子菜单和图标菜单.今天接 ...
随机推荐
- 浅谈贝塞尔曲线以及iOS中粘性动画的实现
关于贝塞尔曲线,网上相关的文章很多,这里我主要想用更简单的方法让大家理解贝塞尔曲线,当然,这仅仅是我个人的理解,如有错误的地方还请大家能够帮忙指出来,这样大家才能一起进步. 贝塞尔曲线,常用到的可分为 ...
- jquery easyui a标记方法传值问题
今天开发一个功能,其操作的按钮式是一个点击的a标记,并且是动态生成的,其点击方法需要传参数具体代码如下 {field:'time',title:'日程时间',width:200,align:'cent ...
- Generic type test java
package test; public class GenericTest { public class Room<T> { private T t; public void add(T ...
- Goldengate进程的合并与拆分规范
Goldengate抽取进程的合并与拆分原则 1. 文档综述 1.1. 文档说明 本文档描述了对GoldenGate的抽取进程进行拆分和合并的基本原则和详细步骤. 1.2. 读者范围 本文 ...
- 深入理解 sudo 与 su 之间的区别
深入理解 sudo 与 su 之间的区别 作者: Himanshu Arora 译者: LCTT zhb127 在早前的一篇文章中,我们深入讨论了 sudo 命令的相关内容.同时,在该文章的末尾有提到 ...
- ES6学习笔记(十四)Generator函数
清明时节雨纷纷,路上行人欲断魂. 借问酒家何处有,牧童遥指杏花村. 二零一九年农历三月初一,清明节. 1.简介 1.1.基本概念 Generator 函数也是 ES6 提供的一种异步编程解决方案,据说 ...
- HDU 4406 GPA
GPA Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 440664 ...
- ArcGIS api for javascript——图形-使用多个图形图层
描述 本例展示了如何增加多个图形图层到地图.一个图形图层显示国家,另一个显示城市.在一个地图中有多个图形图层的能力是在ArcGIS JavaScript API v1.4增加的. 从蓝色的城市点分隔灰 ...
- 分别改动Cube每一个面的贴图UV(Unity3D开发之十八)
猴子原创.欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/46611169 ...
- python list的+,+=,append,extend
面试题之中的一个. def func1(p): p = p + [1] def func2(p): p += [1] p1 = [1,2,3] p2 = [1,2,3] func1(p1) func2 ...