Andriod简单实用mediaPlayer

来源:互联网 发布:windows小马激活工具 编辑:程序博客网 时间:2024/06/05 21:08
Andriod简单实用mediaPlayer
1、首先是播放Activity的UI
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<FrameLayout
android:id="@+id/video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
>
<SurfaceView
android:id="@+id/surfaceView"
style="@style/AppTheme"
android:layout_width="1dp"
android:layout_height="1dp"
android:visibility="gone"
/>

<LinearLayout
android:id="@+id/progressMenu"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:visibility="invisible">
<TextView
android:id="@+id/playTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00:00"
android:textColor="#666"
android:textSize="10sp"
android:visibility="gone"
/>

<SeekBar
android:id="@+id/skbProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0"
android:max="100"
android:thumb="@drawable/seekbar_thumb"
android:paddingLeft="12dip"
android:paddingRight="12dip"
android:visibility="gone"
/>
<TextView
android:id="@+id/totalTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00:00"
android:textColor="#666"
android:textSize="10sp"
android:visibility="gone"/>
</LinearLayout>
</FrameLayout>
</RelativeLayout>
代码解释:
RelativeLayout:相对布局,也就是它里面的控件位置是根据它前一个组件(父组件)而言的,非常灵活
WebView:是给页面做叠加使用的,例如新闻页面上有视频(不想完全用android就这样搞),注意它一定是在最上面的,如果你把它移动到父组件(RelativeLayout)的最下面,后面你会发现视频播放的组件都被webview遮盖了。
FrameLayout:嵌套布局,层次叠堆(做悬浮用这个布局)
SurfaceView:surfaceView 由于是在新的线程中更新画面所以不会阻塞你的UI主线程,视频播放涉及图片更新,所以要用这个组件。
LinearLayout:线性布局,就是里面的组件排成一条线展示。
SeekBar:进度条
注意:android:visibility="gone",这行代码怎么说呢,感觉加载这里没有什么用处,后面activity的onCreate方法里重新有跟它设置了显示属性的。(原因可能是因为activity创建完了,webview加载url里有调用方法设置他们的属性)
2、然后就是activity的代码
packagecom.coship.smartcms;

importandroid.annotation.SuppressLint;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.text.TextUtils;
importandroid.util.Log;
importandroid.view.KeyEvent;
importandroid.view.SurfaceView;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.view.ViewGroup.LayoutParams;
importandroid.view.WindowManager;
importandroid.webkit.JavascriptInterface;
importandroid.webkit.WebView;
importandroid.webkit.WebViewClient;
importandroid.widget.FrameLayout;
importandroid.widget.LinearLayout;
importandroid.widget.RelativeLayout;
importandroid.widget.SeekBar;
importandroid.widget.TextView;

importcom.google.android.gms.appindexing.Action;
importcom.google.android.gms.appindexing.AppIndex;
importcom.google.android.gms.appindexing.Thing;
importcom.google.android.gms.common.api.GoogleApiClient;

public classPartyBuildPlayActivityextendsBaseActivity {

// 视频新闻,是否全屏
private static boolean fullScreen= false;

public staticString webUrl;
// 更新进度条菜单
public static final int UPDATE_PROCESS_MENU= 0;
// 隐藏video
public static final int HIDDEN_VIDEO= 1;
privateWebView webView;
privateSurfaceViewsurfaceView;
privateLinearLayoutprocessMenuLayout;
privateFrameLayoutvideoLayout;
// 播放器类对象
privatePlayer player;
// 进度条
privateSeekBar seekBar;
// 播放时间
privateTextView playTime;
// 总时间
privateTextView totalTime;


privateString pageNo;

HandlermHandler= newHandler() {
@Override
public voidhandleMessage(Message msg) {
switch(msg.what) {
caseUPDATE_PROCESS_MENU:
if(player!= null) {
intposition =player.getCurrentPosition();
intduration =player.getDuration();
totalTime.setText(Util.converSecToHMS(duration));
playTime.setText(Util.converSecToHMS(position));
if(duration >0) {
longpos = seekBar.getMax() * position / duration;
seekBar.setProgress((int) pos);
}
}
break;
caseHIDDEN_VIDEO:
if(player!= null) {
player.release();
player= null;
}
videoLayout.setVisibility(View.INVISIBLE);
processMenuLayout.setVisibility(View.INVISIBLE);
surfaceView.setVisibility(View.INVISIBLE);
seekBar.setVisibility(View.INVISIBLE);
playTime.setVisibility(View.INVISIBLE);
totalTime.setVisibility(View.INVISIBLE);
case3:
videoLayout.setVisibility(View.VISIBLE);
//processMenuLayout.setVisibility(View.VISIBLE);
surfaceView.setVisibility(View.VISIBLE);
seekBar.setVisibility(View.VISIBLE);
playTime.setVisibility(View.VISIBLE);
totalTime.setVisibility(View.VISIBLE);
if(fullScreen) {
processMenuLayout.setVisibility(View.VISIBLE);
}else{
processMenuLayout.setVisibility(View.INVISIBLE);
}
default:
break;
}
}

;
};
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
privateGoogleApiClientclient;

@SuppressLint({"SetJavaScriptEnabled","AddJavascriptInterface"})
@Override
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.partybuildplay);
webView= (WebView) findViewById(R.id.webView);
videoLayout= (FrameLayout)this.findViewById(R.id.video);
surfaceView= (SurfaceView)this.findViewById(R.id.surfaceView);
processMenuLayout= (LinearLayout)this.findViewById(R.id.progressMenu);
seekBar= (SeekBar)this.findViewById(R.id.skbProgress);
playTime= (TextView)this.findViewById(R.id.playTime);
totalTime= (TextView)this.findViewById(R.id.totalTime);
// 设置videoLayout不可见
videoLayout.setVisibility(View.INVISIBLE);
processMenuLayout.setVisibility(View.INVISIBLE);
surfaceView.setVisibility(View.INVISIBLE);
seekBar.setVisibility(View.INVISIBLE);
playTime.setVisibility(View.INVISIBLE);
totalTime.setVisibility(View.INVISIBLE);

webView.getSettings().setJavaScriptEnabled(true);

webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);

webView.getSettings().setDomStorageEnabled(true);

webView.getSettings().setAppCacheMaxSize(1024* 1024* 8);

String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();

webView.getSettings().setAppCachePath(appCachePath);

webView.getSettings().setAllowFileAccess(true);

webView.getSettings().setAppCacheEnabled(true);


webView.setWebViewClient(newWebViewClient() {
@Override
public booleanshouldOverrideUrlLoading(WebView view, String url) {
if(url.startsWith("http") || url.startsWith("https")) {
view.loadUrl(url);
//如果是党建视讯
if(url.indexOf("dj") >0&& url.indexOf("index") <0) {
Log.d("PartyBuildActivity","----------------url:"+ url);

view.loadUrl(url);
}
}else{
Intent intent =newIntent();
intent.setAction("android.intent.action.VIEW");
Log.d(VrBackActivty.class.getSimpleName(),"-------------重写webView加载方法, 传入的url:"+ url);
Uri content_url = Uri.parse(url);
Log.d(VrBackActivty.class.getSimpleName(),"-------------重写webView加载方法,Uri.parse(url)后的content_url:"+ content_url);
intent.setData(content_url);
startActivity(intent);
}
return true;
}
});

webView.addJavascriptInterface(newVideoPlay(this),"videoPlay");

Intent partyPlayIt = getIntent();
if(partyPlayIt !=null) {
String curUrl = partyPlayIt.getStringExtra("url");
String pNo = partyPlayIt.getStringExtra("pageNo");
if(TextUtils.isEmpty(pNo)) {
pageNo= "4";
}else{
pageNo= pNo;
}
Log.d(PartyBuildActivity.class.getSimpleName(),"回调的intent不空,url:"+ curUrl);
webView.loadUrl(curUrl);
}else{
webView.loadUrl(webUrl);
}

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client= newGoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}

/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
publicAction getIndexApiAction() {
Thing object =newThing.Builder()
.setName("PartyBuildPlay Page")//TODO: Define a title for the content shown.
//TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return newAction.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}

@Override
public voidonStart() {
super.onStart();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}

@Override
public voidonStop() {
super.onStop();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}

private classVideoPlay {
privateContext mContext;

publicVideoPlay(Context context) {
this.mContext= context;
}

/**
* 播放视频
*
*@paramheight视频播放界面高
*@paramwidth视频播放界面宽
*@parammarginTop视频播放界面距离上边距的值
*@parammarginLeft视频播放界面距离下边距的值
*/
@JavascriptInterface
public voidplayVideo(String palyUrl,intwidth, intheight,
intmarginTop,intmarginLeft) {

if(player!= null) {
player.reset();
}else{
player= newPlayer(mContext,surfaceView,seekBar,playTime,totalTime,
false,mHandler);
}

Message msg = Message.obtain();
msg.what= 3;
mHandler.sendMessage(msg);

player.playUrl(palyUrl);
LayoutParams params =surfaceView.getLayoutParams();
WindowManager wm = (WindowManager)this.mContext
.getSystemService(Context.WINDOW_SERVICE);
intwWidth = wm.getDefaultDisplay().getWidth();
intwHeight = wm.getDefaultDisplay().getHeight();
params.width= (int) ((float) width / (float)1280* wWidth);
params.height= (int) ((float) height / (float)720* wHeight);


RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams)videoLayout
.getLayoutParams();
intmMarginLeft = (int) ((float) marginLeft / (float)1280* wWidth);
intmMarginTop = (int) ((float) marginTop / (float)720* wHeight);
params2.setMargins(mMarginLeft, mMarginTop,0,0);
}

/**
* 全屏播放视频
*/
@JavascriptInterface
public voidsetFullScreen() {
fullScreen= true;
Message msg = Message.obtain();
msg.what= 3;
mHandler.sendMessage(msg);
intpmWidth =processMenuLayout.getWidth();
intpmHeight =processMenuLayout.getHeight();
ViewGroup parent = (ViewGroup)videoLayout.getParent();
intnWidth = parent.getWidth();
//int nHeight = parent.getHeight() - pmHeight;
intnHeight = parent.getHeight();
LayoutParams params =surfaceView.getLayoutParams();
params.width= nWidth;
params.height= nHeight;
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams)videoLayout
.getLayoutParams();
params2.setMargins(0,0,0,0);
}

/**
* 重置视频的位置
*
*@paramheight
*@paramwidth
*@parammarginTop
*@parammarginLeft
*/
@JavascriptInterface
public voidresetVideoSize(intwidth, intheight, intmarginTop,
intmarginLeft) {
Message msg = Message.obtain();
msg.what= 3;
mHandler.sendMessage(msg);
LayoutParams params =surfaceView.getLayoutParams();
WindowManager wm = (WindowManager)this.mContext
.getSystemService(Context.WINDOW_SERVICE);
intwWidth = wm.getDefaultDisplay().getWidth();
intwHeight = wm.getDefaultDisplay().getHeight();
params.width= (int) ((float) width / (float)1280* wWidth);
params.height= (int) ((float) height / (float)720* wHeight);

RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams)videoLayout
.getLayoutParams();
intmMarginLeft = (int) ((float) marginLeft / (float)1280* wWidth);
intmMarginTop = (int) ((float) marginTop / (float)720* wHeight);
params2.setMargins(mMarginLeft, mMarginTop,0,0);
}

/**
* 前进
*/
@JavascriptInterface
public voidseekToRight() {
player.seekTo(1);
}

/**
* 后退
*/
@JavascriptInterface
public voidseekToLeft() {
player.seekTo(-1);
}


@JavascriptInterface
public voidreleaseVideo() {
if(player!= null) {
Message msg = Message.obtain();
msg.what= 1;
mHandler.sendMessage(msg);
}
}
}

// 处理事件
@Override
public booleandispatchKeyEvent(KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN) {

if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if(fullScreen) {
fullScreen= false;
webView.loadUrl("javascript:resetVideoSize()");
return true;
}else{
if(!webView.canGoBack()) {
if(videoLayout.getVisibility() == View.VISIBLE) {
Message msg = Message.obtain();
msg.what= 1;
mHandler.sendMessage(msg);
}
finish();
//return false;
}else{
if(videoLayout.getVisibility() == View.VISIBLE) {
Message msg = Message.obtain();
msg.what= 1;
mHandler.sendMessage(msg);
}
webView.goBack();
return true;
}
}
}
if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
if(fullScreen) {
if(player!= null) {
player.seekTo(1);
}
}else{
webView.loadUrl("javascript:moveRight()");
return true;
}
}
if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
if(fullScreen) {
if(player!= null) {
player.seekTo(-1);
}
}else{
webView.loadUrl("javascript:moveLeft()");
}
return true;
}
if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP) {
webView.loadUrl("javascript:moveUp()");
return true;
}
if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) {
webView.loadUrl("javascript:moveDown()");
return true;
}
if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER
|| event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) {
webView.loadUrl("javascript:doConfirm()");
return true;
}
}
return super.dispatchKeyEvent(event);
}

}
ps:里面按钮事件的响应调用的都是webview加载的页面上的js。大家关键看里面的onCreate里的查找view的几个方法、
playVideo播放视频、setFullScreen全屏播放、resetVideoSize重置视频播放界面大小、Handler方法。
3、再就是player的播控对象了
packagecom.coship.smartcms;
importjava.io.IOException;
importjava.util.Timer;
importjava.util.TimerTask;

importandroid.annotation.SuppressLint;
importandroid.content.Context;
importandroid.media.AudioManager;
importandroid.media.MediaPlayer;
importandroid.media.MediaPlayer.OnBufferingUpdateListener;
importandroid.media.MediaPlayer.OnCompletionListener;
importandroid.media.MediaPlayer.OnErrorListener;
importandroid.media.MediaPlayer.OnInfoListener;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.util.Log;
importandroid.view.SurfaceHolder;
importandroid.view.SurfaceView;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.view.ViewGroup.LayoutParams;
importandroid.widget.LinearLayout;
importandroid.widget.SeekBar;
importandroid.widget.TextView;
importandroid.widget.Toast;
public classPlayer implementsOnBufferingUpdateListener,
OnCompletionListener, MediaPlayer.OnPreparedListener,
SurfaceHolder.Callback ,OnErrorListener{
private final static intspeed= 15 * 1000;
private booleanfullScreen=false;
private static booleanisSurfaceCreated=false;
private intvideoWidth;
private intvideoHeight;
publicMediaPlayermediaPlayer;
privateSurfaceHoldersurfaceHolder;
privateSurfaceViewsurfaceView;
privateSeekBar skbProgress;
privateTextView playTime;
privateTextView totalTime;
privateHandler mHandler;
privateTimer mTimer=newTimer();
privateContext context;
publicPlayer(Context con,SurfaceView surfaceView,SeekBar skbProgress,TextView playTime,TextView totalTime,booleanfullScreen, Handler mHandler)
{
this.context= con;
this.skbProgress=skbProgress;
this.playTime= playTime;
this.totalTime= totalTime;
this.surfaceView= surfaceView;
this.fullScreen= fullScreen;
this.mHandler= mHandler;
surfaceHolder=surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mediaPlayer= newMediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnPreparedListener(this);
mTimer.schedule(mTimerTask,0,1000);
}
TimerTaskmTimerTask= newTimerTask()
{
@Override
public voidrun() {
if(mediaPlayer== null)
return;
if(mHandler!= null&& mediaPlayer.isPlaying()) {
mHandler.sendEmptyMessage(0);
}
}
};
public intgetCurrentPosition(){
if(mediaPlayer!= null&& mediaPlayer.isPlaying()){
returnmediaPlayer.getCurrentPosition();
}
return0;
}
public intgetDuration(){
if(mediaPlayer!= null&& mediaPlayer.isPlaying()){
returnmediaPlayer.getDuration();
}
return0;
}
public voidplayUrl(String videoUrl)
{
try{
if(mediaPlayer!= null){
mediaPlayer.reset();
mediaPlayer.setDataSource(videoUrl);
mediaPlayer.prepareAsync();
}
}catch(IllegalArgumentException e) {
e.printStackTrace();
}catch(IllegalStateException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}
}
public voidpauseOrStart()
{
if(mediaPlayer.isPlaying()){
mediaPlayer.pause();
}else{
mediaPlayer.start();
}
}
@Override
public voidsurfaceChanged(SurfaceHolder arg0,intarg1, intarg2, intarg3) {
Log.e("mediaPlayer","surface changed");
}
@Override
public voidsurfaceCreated(SurfaceHolder arg0) {
//Toast.makeText(context, "surfaceCreated", Toast.LENGTH_LONG).show();
isSurfaceCreated=true;
}
@Override
public voidsurfaceDestroyed(SurfaceHolder arg0) {
Log.e("mediaPlayer","surface destroyed");
isSurfaceCreated=false;
}
@Override
public voidonPrepared(MediaPlayer mediaPlayer) {
videoWidth= mediaPlayer.getVideoWidth();
videoHeight= mediaPlayer.getVideoHeight();
if(videoHeight!= 0 && videoWidth!= 0) {
//Toast.makeText(context, "onPrepared", Toast.LENGTH_LONG).show();
if(isSurfaceCreated){
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.start();
}
// resetSurfaceSize(surfaceView,videoWidth,videoHeight);
}
Log.e("mediaPlayer","onPrepared");
}
@Override
public voidonCompletion(MediaPlayer arg0) {
//TODO Auto-generated method stub
}
@Override
public voidonBufferingUpdate(MediaPlayer arg0,intbufferingProgress) {
if(skbProgress!= null){
skbProgress.setSecondaryProgress(bufferingProgress);
intcurrentProgress=skbProgress.getMax()*mediaPlayer.getCurrentPosition()/mediaPlayer.getDuration();
Log.e(currentProgress+"% play", bufferingProgress +"% buffer");
}
}
//-1块退,1快进
public voidseekTo(inttype){
if(mediaPlayer.isPlaying()){
intposition =mediaPlayer.getCurrentPosition();
intduration =mediaPlayer.getDuration();
if(type == -1){
if(speed> position){
mediaPlayer.seekTo(0);
skbProgress.setProgress(0);
}else{
intnewPosition = position -speed;
mediaPlayer.seekTo(position - speed);
longpos = skbProgress.getMax() * newPosition / duration;
skbProgress.setProgress((int) pos);
}
}
if(type == 1){
if(speed+ position > duration){
mediaPlayer.seekTo(duration);
}else{
intnewPosition = position +speed;
mediaPlayer.seekTo(newPosition);
longpos = skbProgress.getMax() * newPosition / duration;
skbProgress.setProgress((int) pos);
}
}
}
}
//根据设置和视频尺寸,调整视频播放区域的大小
private voidresetSurfaceSize(finalView view,intvideoWidth,intvideoHeight){
ViewGroup parent= (ViewGroup) view.getParent();
intwidth=parent.getWidth();
intheight=parent.getHeight();
intnWidth = 0;
intnHeight =0;

if(width>0&&height>0){
if(fullScreen){
nWidth = width;
nWidth = height;
}
else{
if(videoWidth > width){
nWidth = width;
floatp = (float)width/videoWidth;
nHeight = (int) ((int)videoHeight * p);
}else{
nWidth = width;
nWidth = height;
}
}
}
Message.obtain(mHandler,1, nWidth, nHeight).sendToTarget();
}
public voidrelease(){
if(mediaPlayer!= null){
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer= null;
}
}

public voidreset(){
if(mediaPlayer!= null){
mediaPlayer.stop();
mediaPlayer.reset();
}
}
public booleanonError(MediaPlayer arg0,intarg1, intarg2) {
Toast.makeText(context, arg1+"&&"+arg2, Toast.LENGTH_LONG).show();
return false;
}
}
4、html页面调用方法
videoPlay.playVideo(palyUrl,290,210,265, 132);播放,playurl为视频源url
videoPlay.releaseVideo();关闭播放器
videoPlay.resetVideoSize(290,210,265, 132);重置位置
js里能够这样调用,都是因为onCreate里方法里webView.addJavascriptInterface(newVideoPlay(this),"videoPlay");(将后台VidePlay对象绑定videoPlay传到前台使用),webView.getSettings().setJavaScriptEnabled(true);开启js方法调用支持
以及方法上面使用的注解@SuppressLint({"SetJavaScriptEnabled","AddJavascriptInterface"})支持
5、顺便附上使用的播控样式文件,不然原生的进度条可不好看哦
<?xml version="1.0"encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android">
<!-- 按下状态-->
<item
android:state_focused="true"
android:state_pressed="true">
<shape>
<cornersandroid:radius="8dp"/>
<sizeandroid:width="8dp"
android:height="8dp"/>
<solidandroid:color="#ffffff"/>
</shape>
</item>
<!--普通无焦点状态 -拖动按钮-->
<item
android:state_focused="false"
android:state_pressed="false">
<shape>
<cornersandroid:radius="8dp"/>
<sizeandroid:width="8dp"
android:height="8dp"/>
<solidandroid:color="#ffffff"/>
</shape>

</item>
<!-- 有焦点状态-->
<item
android:state_focused="true"
android:state_pressed="false">
<shape>
<cornersandroid:radius="8dp"/>
<sizeandroid:width="8dp"
android:height="8dp"/>
<solidandroid:color="#ffffff"/>
</shape>
</item>
<!-- 有焦点 -->
<item
android:state_focused="true">
<shape>
<cornersandroid:radius="8dp"/>
<sizeandroid:width="8dp"
android:height="8dp"/>
<solidandroid:color="#ffffff"/>
</shape>
</item>
</selector>

支持简单的快退快进(1s的步进,按一下按键是1s)。至此关键的代码都已梳理完,以后使用mediaplayer就可以直接套用,注意player类可以共用哦。
0 0
原创粉丝点击