基于 exoplayer 的 videoview
2017-08-22 14:07
344 查看
ExoPlayerView
项目地址:JarvanMo/ExoPlayerView简介:基于 exoplayer 的 videoview更多:作者 提 Bug 标签:videoview-exoplayer-视频-直播-ExoPlayerView is a simple video view based on ExoPlayer.中文.
Features
1.There are 4 modes to resize the video: fit , fit_width , fit_height and none. 2.Process AudioFocus automatically. 3.Change its orientation by sensor automatically 4.simple gesture action supported.UsageImportAdd the following to your
build.gradlefile
compile 'com.jarvanmo:exoplayerview:1.0.7'ExoPlayerView can play simple video directly, such as mp4,m3u8 and so on. It's easy to use. Declare ExoVideoView in your layout files:
<com.jarvanmo.exoplayerview.ui.ExoVideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="300dp" app:useController="true" app:resizeMode="fit" app:orientationAuto="true" />Playplay a video :
videoView.play(mediaSource);The ExoVideoView will create SimpleExoPlayer by itself if we play mediaSource. Actually, you can set a player by yourself;
videoView.setPlayer(player);We can play from a particular position too:
videoView.play(mediaSource,where);Note:don't forget to release ExoPlayer:
videoView.releaseSelfPlayer();also we can give a display name:
mediaSource.setDisplayName("LuYu YouYue");or
videoView.setDisplayName("LuYu YouYue");Manage OrientationThe ExoVideoView can change its orientation by sensor automatically only when you set a not-null orientation listener:
videoView.setOrientationListener(new ExoVideoPlaybackControlView.OrientationListener() { @Override public void onOrientationChange(@ExoVideoPlaybackControlView.SensorOrientationType int orientation) { if(orientation == SENSOR_PORTRAIT){ changeToPortrait(); }else if(orientation == SENSOR_LANDSCAPE){ changeToLandscape(); } } });When the ExoVideoView change its orientation by itself,The ExoVideoView will call
activity.setRequestedOrientation()if the context in controller is an Activity. The fullscreen button is the same.You can change the orientation of ExoVideoView by:
videoView.toggleControllerOrientation();Or
videoView.setPortrait(true);Handle Back EventsIn activity :
When button in controller clicked:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){
if(videoView.isPortrait()){
finish();
return false;
}else {
videoView.toggleControllerOrientation();return true;
}
}
return super.onKeyDown(keyCode, event);
}
videoView.setBackListener(new ExoVideoPlaybackControlView.ExoClickListener() { @Override public boolean onClick(View view, boolean isPortrait) { if(isPortrait){ finish(); } return false; } });if
onClick()return true,it'll interrupt controller's operation.If it return false and you set a not-null OrientationListener,The ExoVideoView will request to change its orientation automatically.If the ExoVideoView's orientation is landscape, it'll be changed to portrait and
OrientationLister.onOrientationChange()will be called.OthersAlso you can add you view to the controller view when landscape:
videoView.addViewToControllerWhenLandscape(view);the view you want to add will add into FrameLayout.NOTENever forget to release the ExoPlayer.
videoView.releaseSelfPlayer();or
player.release();
相关文章推荐
- 基于google ExoPlayer 简单自定义播放界面
- 一款基于ExoPlayer的自定义播放器(已开源)
- 一款基于ExoPlayer的自定义播放器(已开源)
- 一个基于 exosip 库的 UAC 和 UAS 的代码整理
- ExoPlayer 的小解析
- EXoPlayer Developer guide
- Exoplayer使用记录4-调节音轨中某个频道的声音
- 一个基于 exosip 库的 UAC 和 UAS 的代码整理
- android 视频播放 Google exoplayer
- [置顶] 我的GB28181标准开发里程碑——基于eXosip的IPC端与SPVMN注册成功
- EasyPlayerPro基于FFMPEG实现播放同时进行录像的功能
- 【基于QMediaPlayer的简易视频播放器】— 2、QMediaPlayer的基本使用
- Mediacodec学习(EXOPlayer分析)
- 一个基于exosip的软电话例子
- 一步步搭建视频直播系统,基于LFLiveKit+ijkplayer+rtmp(iOS端)
- 基于Composer Player 模型加载和相关属性设置
- 使用C#打造自己的mp3播放器(基于Windows Media Player内核)
- ExoPlayer结构分析
- 【MFC】基于windows media player的音乐播放器
- 【MFC】基于windows media player的音乐播放器