android视频播放器-源码.doc_第1页
android视频播放器-源码.doc_第2页
android视频播放器-源码.doc_第3页
android视频播放器-源码.doc_第4页
android视频播放器-源码.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本文讲的是“android 视频播放器”,并附有播放器源代码1开发环境: eclipse3.6 ADT-0.9.7 AVD1.62程序运行效果A启动AVD(虚拟设备)在应用程序界面主界面,我们可以看到“艾文播放器”B点击打开后,会播放默认的一个coco的广告C点击标题栏的按钮可以打开文件浏览器D点击视频文件,会提示使用的播放器E选择“艾文视频播放器”打开后,按ctrl+f12,切换到横屏,发现视频并没有中断,而是继续播放3源码分析A图片都是网上找的,还有就是自己收藏的地方翻出来的,不多讲了。B布局文件main.xml:期中包含一个videoview,用于播放视频图像titlebar.xml:主视图的标题栏布局,主要用于添加一个菜单按钮,点击后打开文件浏览器myfile.xml:为文件浏览器布局CVideoPlay.javaview plaincopy to clipboardprint?1. packagecom.bestaone; 2. 3. importandroid.app.Activity; 4. importandroid.content.Intent; 5. .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. /打开MyFileactivity 41. 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. MyFile.javaview plaincopy to clipboardprint?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. .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. privatefinalStringFILE_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. privateListitems=null;/items:存放显示的名称 37. privateListpaths=null;/paths:存放文件路径 38. privateListsizes=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(Bundleicicle) 69. super.onCreate(icicle); 70. setContentView(R.layout.myfile); 71. 72. path_edit=(EditText)findViewById(R.id.path_edit); 73. rb_qry=(ImageButton)findViewById(R.id.qry_button); 74. rb_qry.setOnClickListener(listener_qry); 75. getListView().setOnItemLongClickListener(this); 76. getFileDir(rootPath); 77. 78. 79. Button.OnClickListenerlistener_qry=newButton.OnClickListener() 80. publicvoidonClick(Viewarg0) 81. Filefile=newFile(path_edit.getText().toString(); 82. if(file.exists() 83. if(file.isFile() 84. openFile(file); 85. else 86. getFileDir(path_edit.getText().toString(); 87. 88. else 89. Toast.makeText(MyFile.this,找不到该位置,请确定位置是否正确!,Toast.LENGTH_SHORT).show(); 90. 91. 92. ; 93. 94. /* 95. *设置ListItem被点击时要做的动作 96. */97. Override98. protectedvoidonListItemClick(ListViewl,Viewv,intposition,longid) 99. Filefile=newFile(paths.get(position); 100. fileOrDirHandle(file); 101. 102. 103. 104. /* 105. *处理文件或者目录的方法 106. *paramfile 107. *paramflag 108. */109. privatevoidfileOrDirHandle(finalFilefile) 110. if(file.isDirectory() 111. getFileDir(file.getPath(); 112. else 113. openFile(file); 114. 115. 116. 117. /* 118. *取得文件结构的方法 119. *paramfilePath 120. */121. privatevoidgetFileDir(StringfilePath) 122. /*设置目前所在路径*/123. path_edit.setText(filePath); 124. items=newArrayList(); 125. paths=newArrayList(); 126. sizes=newArrayList(); 127. Filef=newFile(filePath); 128. Filefiles=f.listFiles(); 129. if(files!=null) 130. /*将所有文件添加ArrayList中*/131. for(inti=0;ifiles.length;i+) 132. if(filesi.isDirectory() 133. items.add(filesi.getName(); 134. paths.add(filesi.getPath(); 135. sizes.add(); 136. 137. 138. 139. for(inti=0;i0) 144. StringendName=fileName.substring(index,fileName.length().toLowerCase(); 145. Stringtype=null; 146. for(intx=0;xFILE_MapTable.length;x+) 147. /支持的格式,才会在文件浏览器中显示 148. if(endName.equals(FILE_MapTablex0) 149. type=FILE_MapTablex1; 150. break; 151. 152. 153. if(type!=null) 154. items.add(filesi.getName(); 155. paths.add(filesi.getPath(); 156. sizes.add(MyUtil.fileSizeMsg(filesi); 157. 158. 159. 160. 161. 162. /*使用自定义

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论