如何定制化Android的播放器(VideoViewEx.java,MediaControllerEx.java,模仿RockPlayer的界面)
来源:互联网 发布:mac开机密码怎么设置 编辑:程序博客网 时间:2024/06/07 22:30
Introduction
Customized Player-This article interpret how to implement a customized video player instead of the UI of android’s MediaController and how to handle error of android’s MediaPlayer to enable it continue replaying from the last position after reset the engine of media player
Background
I have googled lots of open source player for android, unfortunately almost all of the players are just for music but not for video, audio isn’t easy to play failed compared with video, I implement the customized player to enable developer easy to modify controller UI of media player and pay attention to the drawback of VideoView control provided by Android
Using the code
Android provide MediaPlayer and VideoView/MediaController to create player, but if dislike the UI and hope to redesign a player to enable it increasing more features such as adjusting volume or full screen , you can refer to my customized player code , it include 3 files, MediaControllerEx.java, VideoViewEx.java, PlayerActivity.java, MediaControllerEx.java implement the controller UI layout for player,if you want to adjust the SeekBar height, you should replace the default style with your customized style.
// layout your own UI for controller
protected View makeControllerView() {
LayoutInflater inflate = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mRoot = inflate.inflate(R.layout.media_controller_view, null);
initControllerView(mRoot);
return mRoot;
}
//SeekBar style for controller
<style name="player_seekbar">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@drawable/seekbar_style_drawable</item>
<item name="android:indeterminateDrawable">@drawable/seekbar_style_drawable</item>
<item name="android:minHeight">10dip</item>
<item name="android:maxHeight">10dip</item>
<item name="android:thumb">@drawable/controller_playhead_drawable</item>
<item name="android:thumbOffset">8px</item>
<item name="android:focusable">true</item>
</style>
//assign the seek position when setting video path in VideoViewEx.java
public void setVideoPath(String path,int position) {
setVideoURI(Uri.parse(path),position);
}
/**
* The MediaPlayer often change to error state when playing video,and then prompt "can't play this video" dialog, so you have to handle these error via remembering the played time and replaying video after reset MediaPlayer engine
*/
private MediaPlayer.OnErrorListener mOnErrorListener = new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
switch (what) {
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
Toast.makeText(PlayerActivity.this, "MEDIA_ERROR_SERVER_DIED",
Toast.LENGTH_SHORT).show();
showErrorDlg(what);
return true;
case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
Toast.makeText(PlayerActivity.this,
"MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK",
Toast.LENGTH_SHORT).show();
break;
case MediaPlayer.MEDIA_ERROR_UNKNOWN:
Toast.makeText(PlayerActivity.this, "MEDIA_ERROR_UNKNOWN",
Toast.LENGTH_SHORT).show();
break;
}
setProgressContainer(true, getString(R.string.msg_handle_error));
int position=mVideoView.getCurrentPosition();
if(position>0){
mCurPosition=position;
}
mVideoView.setVideoPath(mCurrentMediaUrl,position);
return true;
}
};
Points of Interest
My interest includes streaming player, decoder/encoder/demuxer of android's openCore media framework
History
CustomizedPlayer 0.1 version.
备注:懒得用中文再描述一遍,需要继续完善的地方是如何在播放过程中有相应的提示信息(如正在缓冲,网络断线,出错处理等)
- Download Customized Player
- 如何定制化Android的播放器(VideoViewEx.java,MediaControllerEx.java,模仿RockPlayer的界面)
- android的界面定制
- Java模仿DOS界面
- Android 定制化自己的解锁界面
- Android定制化自己的开锁界面
- android 启动界面的定制
- android 启动界面的定制
- 如何定制自己的java service: example
- Java聊天室,界面模仿QQ
- 如何定制Domino平台的登录界面
- 如何定制Domino平台的登录界面
- 关于迅雷播放器的模仿
- Android(定制的ListView的界面)
- 基于ijkplayer封装支持简单界面UI定制的视频播放器
- 【Android】42、定制ListView 的界面
- 定制android的开机启动界面
- 模仿音乐播放器带进度的播放暂停按钮
- 自己模仿QQ基于Java Swing做的一个QQ界面
- 驱动级模拟驱动级模拟:直接读写键盘的硬件端口!
- 1.1 VxWorks System Tasks (VxWorks的系统Tasks)
- Linux内核配置系统浅析
- Ex3.11 对startActivityForResult的理解
- Nested classes
- 如何定制化Android的播放器(VideoViewEx.java,MediaControllerEx.java,模仿RockPlayer的界面)
- 贴片电容在封装上怎么看电容的阻值
- poj 1149
- STM8S105 SPI 初始化
- android系统访问自己的tomcat服务器下的项目不能访问的原因
- 有理想的程序员必须知道的15件事
- poj 1639
- 【破解作品】Shinesoft Video to AVI Converter 3.00 破解补丁
- plsql