您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > android视频播放器-源码
本文讲的是“android视频播放器”,并附有播放器源代码1.开发环境:eclipse3.6ADT-0.9.7AVD1.62.程序运行效果A.启动AVD(虚拟设备)在应用程序界面主界面,我们可以看到“艾文播放器”B.点击打开后,会播放默认的一个coco的广告C.点击标题栏的按钮可以打开文件浏览器D.点击视频文件,会提示使用的播放器E.选择“艾文视频播放器”打开后,按ctrl+f12,切换到横屏,发现视频并没有中断,而是继续播放3.源码分析A.图片都是网上找的,还有就是自己收藏的地方翻出来的,不多讲了。B.布局文件main.xml:期中包含一个videoview,用于播放视频图像titlebar.xml:主视图的标题栏布局,主要用于添加一个菜单按钮,点击后打开文件浏览器myfile.xml:为文件浏览器布局C.VideoPlay.javaviewplaincopytoclipboardprint?1.packagecom.bestaone;2.3.importandroid.app.Activity;4.importandroid.content.Intent;5.importandroid.net.Uri;6.importandroid.os.Bundle;7.importandroid.util.Log;8.importandroid.view.View;9.importandroid.view.View.OnClickListener;10.importandroid.view.Window;11.importandroid.view.WindowManager;12.importandroid.widget.ImageButton;13.importandroid.widget.MediaController;14.importandroid.widget.TextView;15.importandroid.widget.VideoView;16.17.publicclassVideoPlayextendsActivity{18.19.privateVideoViewvideoView;20.privatestaticintindex=0;21.22.@Override23.publicvoidonCreate(BundlesavedInstanceState){24.super.onCreate(savedInstanceState);25.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);26.setContentView(R.layout.main);27.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//28.//设置标题栏的布局29.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);30.//这个空间暂时没用31.finalTextViewtitleTV=(TextView)findViewById(R.id.title);32.titleTV.setText();33.ImageButtontitleButton=(ImageButton)findViewById(R.id.titleButton);34.//为按钮添加鼠标点击事件35.titleButton.setOnClickListener(newOnClickListener(){36.@Override37.publicvoidonClick(Viewv){38.Intentintent=newIntent();39.intent.setClass(VideoPlay.this,MyFile.class);40.//打开MyFileactivity41.startActivity(intent);42.}43.});44.Intentintent=getIntent();45.Stringvalue=intent.getDataString();46.videoView=(VideoView)findViewById(R.id.VideoView01);47.if(value==null){48.//加载默认视频49.videoView.setVideoURI(Uri.parse(android.resource://com.bestaone/+R.drawable.coco));50.}else{51.//通过文件浏览器传过来的视频路径,播放52.videoView.setVideoPath(value);53.}54.videoView.setMediaController(newMediaController(VideoPlay.this));55.videoView.requestFocus();56.}57.58.//启动59.@Override60.protectedvoidonStart(){61.super.onStart();62.Log.i(mp4,@@@onstart);63.}64.65.@Override66.protectedvoidonResume(){67.super.onResume();68.videoView.seekTo(index);69.videoView.start();70.Log.i(mp4,@@@onresume);71.}72.73.//暂停74.@Override75.protectedvoidonPause(){76.super.onPause();77.Log.i(mp4,@@@onpause);78.}79.80.//停止81.@Override82.protectedvoidonStop(){83.super.onStop();84.videoView.pause();85.//在这里记住视频播放的位置,当屏幕横竖切换的时候可以从记录点继续播放86.index=videoView.getCurrentPosition();87.Log.i(mp4,@@@onstop);88.}89.90.//销毁91.@Override92.protectedvoidonDestroy(){93.super.onDestroy();94.//videoView.destroyDrawingCache();95.index=videoView.getCurrentPosition();96.Log.i(mp4,@@@ondestroy);97.}98.99.}packagecom.bestaone;importandroid.app.Activity;importandroid.content.Intent;importandroid.net.Uri;importandroid.os.Bundle;importandroid.util.Log;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.view.Window;importandroid.view.WindowManager;importandroid.widget.ImageButton;importandroid.widget.MediaController;importandroid.widget.TextView;importandroid.widget.VideoView;publicclassVideoPlayextendsActivity{MyFile.javaviewplaincopytoclipboardprint?1.packagecom.bestaone;2.3.importjava.io.File;4.importjava.util.ArrayList;5.importjava.util.List;6.7.importandroid.app.ListActivity;8.importandroid.content.Intent;9.importandroid.net.Uri;10.importandroid.os.Bundle;11.importandroid.view.KeyEvent;12.importandroid.view.View;13.importandroid.widget.AdapterView;14.importandroid.widget.AdapterView.OnItemLongClickListener;15.importandroid.widget.Button;16.importandroid.widget.EditText;17.importandroid.widget.ImageButton;18.importandroid.widget.ListView;19.importandroid.widget.TextView;20.importandroid.widget.Toast;21.22.publicclassMyFileextendsListActivityimplementsOnItemLongClickListener{23.24.//支持的视频格式25.privatefinalString[][]FILE_MapTable={26.27.//{后缀名,MIME类型}28.{.3gp,video/3gpp},29.{.mov,video/quicktime},30.{.avi,video/x-msvideo},31.{.rmvb,audio/x-pn-realaudio},32.{.wmv,audio/x-ms-wmv}33.34.};35.36.privateListStringitems=null;//items:存放显示的名称37.privateListStringpaths=null;//paths:存放文件路径38.privateListStringsizes=null;//sizes:文件大小39.privateStringrootPath=/;//rootPath:起始文件夹40.privateTextViewpath_edit;41.privateImageButtonrb_qry;42.privateintisZoom=0;43.privateintisOpen=0;44.45.46./**47.*重写返回键功能:返回上一级文件夹48.*/49.@Override50.publicbooleanonKeyDown(intkeyCode,KeyEventevent){51.//是否触发按键为back键52.if(keyCode==KeyEvent.KEYCODE_BACK){53.path_edit=(EditText)findViewById(R.id.path_edit);54.Filefile=newFile(path_edit.getText().toString());55.if(rootPath.equals(path_edit.getText().toString())){56.returnsuper.onKeyDown(keyCode,event);57.}else{58.getFileDir(file.getParent());59.returntrue;60.}61.//如果不是back键正常响应62.}else{63.returnsuper.onKeyDown(keyCode,event);64.}65.}66.67.@Override68.protectedvoidonCreate(Bundleic
本文标题:android视频播放器-源码
链接地址:https://www.777doc.com/doc-3629874 .html