android视频播放器源码.docx

上传人:b****2 文档编号:681922 上传时间:2023-04-29 格式:DOCX 页数:17 大小:181.41KB
下载 相关 举报
android视频播放器源码.docx_第1页
第1页 / 共17页
android视频播放器源码.docx_第2页
第2页 / 共17页
android视频播放器源码.docx_第3页
第3页 / 共17页
android视频播放器源码.docx_第4页
第4页 / 共17页
android视频播放器源码.docx_第5页
第5页 / 共17页
android视频播放器源码.docx_第6页
第6页 / 共17页
android视频播放器源码.docx_第7页
第7页 / 共17页
android视频播放器源码.docx_第8页
第8页 / 共17页
android视频播放器源码.docx_第9页
第9页 / 共17页
android视频播放器源码.docx_第10页
第10页 / 共17页
android视频播放器源码.docx_第11页
第11页 / 共17页
android视频播放器源码.docx_第12页
第12页 / 共17页
android视频播放器源码.docx_第13页
第13页 / 共17页
android视频播放器源码.docx_第14页
第14页 / 共17页
android视频播放器源码.docx_第15页
第15页 / 共17页
android视频播放器源码.docx_第16页
第16页 / 共17页
android视频播放器源码.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

android视频播放器源码.docx

《android视频播放器源码.docx》由会员分享,可在线阅读,更多相关《android视频播放器源码.docx(17页珍藏版)》请在冰点文库上搜索。

android视频播放器源码.docx

android视频播放器源码

本文讲的是“android视频播放器”,并附有播放器源代码

1.开发环境:

 eclipse3.6

 ADT-0.9.7

 AVD1.6

 2.程序运行效果

A.启动AVD(虚拟设备)在应用程序界面主界面,我们可以看到“艾文播放器”

 

B.点击打开后,会播放默认的一个coco的广告

 

C.点击标题栏的按钮可以打开文件浏览器

 

D.点击视频文件,会提示使用的播放器

 

E.选择“艾文视频播放器”打开后,按ctrl+f12,切换到横屏,发现视频并没有中断,而是继续播放

 

3.源码分析

A.图片都是网上找的,还有就是自己收藏的地方翻出来的,不多讲了。

B.布局文件

main.xml:

期中包含一个videoview,用于播放视频图像

titlebar.xml:

主视图的标题栏布局,主要用于添加一个菜单按钮,点击后打开文件浏览器

myfile.xml:

为文件浏览器布局

 

C.VideoPlay.java

viewplaincopytoclipboardprint?

1.package com.bestaone;  

2.  

3.import android.app.Activity;  

4.import android.content.Intent;  

5.import .Uri;  

6.import android.os.Bundle;  

7.import android.util.Log;  

8.import android.view.View;  

9.import android.view.View.OnClickListener;  

10.import android.view.Window;  

11.import android.view.WindowManager;  

12.import android.widget.ImageButton;  

13.import android.widget.MediaController;  

14.import android.widget.TextView;  

15.import android.widget.VideoView;  

16.  

17.public class VideoPlay extends Activity {  

18.  

19.    private VideoView videoView;  

20.    private static int index = 0;  

21.  

22.    @Override  

23.    public void onCreate(Bundle savedInstanceState) {  

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.        final TextView titleTV = (TextView) findViewById(R.id.title);  

32.        titleTV.setText("");  

33.        ImageButton titleButton = (ImageButton) findViewById(R.id.titleButton);  

34.        //为按钮添加鼠标点击事件  

35.        titleButton.setOnClickListener(new OnClickListener() {  

36.            @Override  

37.            public void onClick(View v) {  

38.                Intent intent = new Intent();  

39.                intent.setClass(VideoPlay.this, MyFile.class);   

40.                //打开MyFile activity  

41.                startActivity(intent);    

42.            }  

43.        });  

44.        Intent intent = getIntent();  

45.        String value = 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(new MediaController(VideoPlay.this));  

55.        videoView.requestFocus();  

56.    }  

57.  

58.    //启动  

59.    @Override  

60.    protected void onStart() {  

61.        super.onStart();  

62.        Log.i("mp4", "@@@ on start");  

63.    }  

64.  

65.    @Override  

66.    protected void onResume() {  

67.        super.onResume();  

68.        videoView.seekTo(index);  

69.        videoView.start();  

70.        Log.i("mp4", "@@@ on resume");  

71.    }  

72.  

73.    //暂停  

74.    @Override  

75.    protected void onPause() {  

76.        super.onPause();  

77.        Log.i("mp4", "@@@ on pause");  

78.    }  

79.  

80.    //停止  

81.    @Override  

82.    protected void onStop() {  

83.        super.onStop();  

84.        videoView.pause();  

85.        //在这里记住视频播放的位置,当屏幕横竖切换的时候可以从记录点继续播放  

86.        index = videoView.getCurrentPosition();  

87.        Log.i("mp4", "@@@ on stop");  

88.    }  

89.  

90.    //销毁  

91.    @Override  

92.    protected void onDestroy() {  

93.        super.onDestroy();  

94.        // videoView.destroyDrawingCache();  

95.        index = videoView.getCurrentPosition();  

96.        Log.i("mp4", "@@@ on destroy");  

97.    }  

98.  

99.}  

 

MyFile.java

viewplaincopytoclipboardprint?

1.package com.bestaone;  

2.  

3.import java.io.File;  

4.import java.util.ArrayList;  

5.import java.util.List;  

6.  

7.import android.app.ListActivity;  

8.import android.content.Intent;  

9.import .Uri;  

10.import android.os.Bundle;  

11.import android.view.KeyEvent;  

12.import android.view.View;  

13.import android.widget.AdapterView;  

14.import android.widget.AdapterView.OnItemLongClickListener;  

15.import android.widget.Button;  

16.import android.widget.EditText;  

17.import android.widget.ImageButton;  

18.import android.widget.ListView;  

19.import android.widget.TextView;  

20.import android.widget.Toast;  

21.  

22.public class MyFile extends ListActivity implements OnItemLongClickListener {  

23.      

24.    //支持的视频格式  

25.    private final String[][] 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.    private List items = null; // items:

存放显示的名称  

37.    private List paths = null; // paths:

存放文件路径  

38.    private List sizes = null; // sizes:

文件大小  

39.    private String rootPath = "/"; // rootPath:

起始文件夹  

40.    private TextView path_edit;  

41.    private ImageButton rb_qry;  

42.    private int isZoom = 0;  

43.    private int isOpen = 0;  

44.  

45.  

46.    /** 

47.     * 重写返回键功能:

返回上一级文件夹 

48.     */  

49.    @Override  

50.    public boolean onKeyDown(int keyCode, KeyEvent event) {  

51.        // 是否触发按键为back键  

52.        if (keyCode == KeyEvent.KEYCODE_BACK) {  

53.            path_edit = (EditText) findViewById(R.id.path_edit);  

54.            File file = new File(path_edit.getText().toString());  

55.            if (rootPath.equals(path_edit.getText().toString())) {  

56.                return super.onKeyDown(keyCode, event);  

57.            } else {  

58.                getFileDir(file.getParent());  

59.                return true;  

60.            }  

61.            // 如果不是back键正常响应  

62.        } else {  

63.            return super.onKeyDown(keyCode, event);  

64.        }  

65.    }  

66.  

67.    @Override  

68.    protected void onCreate(Bundle icicle) {  

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.OnClickListener listener_qry = new Button.OnClickListener() {  

80.        public void onClick(View arg0) {  

81.            File file = new File(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.    @Override  

98.    protected void onListItemClick(ListView l, View v, int position, long id) {  

99.        File file = new File(paths.get(position));  

100.        fileOrDirHandle(file);  

101.    }  

102.  

103.  

104.    /** 

105.     * 处理文件或者目录的方法 

106.     * @param file 

107.     * @param flag 

108.     */  

109.    private void fileOrDirHandle(final File file) {  

110.        if (file.isDirectory()) {  

111.            getFileDir(file.getPath());  

112.        } else {  

113.            openFile(file);  

114.        }  

115.    }  

116.  

117.    /** 

118.     * 取得文件结构的方法 

119.     * @param filePath 

120.     */  

121.    private void getFileDir(String filePath) {  

122.        /* 设置目前所在路径 */  

123.        path_edit.setText(filePath);  

124.        items = new ArrayList();  

125.        paths = new ArrayList();  

126.        sizes = new ArrayList();  

127.        File f = new File(filePath);  

128.        File[] files = f.listFiles();  

129.        if (files !

= null) {  

130.            /* 将所有文件添加ArrayList中 */  

131.            for (int i = 0; i < files.length; i++) {  

132.                if (files[i].isDirectory()) {  

133.                    items.add(files[i].getName());  

134.                    paths.add(files[i].getPath());  

135.                    sizes.add("");  

136.                }  

137.            }  

138.              

139.            for (int i = 0; i < files.length; i++) {  

140.                if (files[i].isFile()) {  

141.                    String fileName = files[i].getName();  

142.                    int index = fileName.lastIndexOf(".");  

143.                    if(index>0){  

144.                        String endName = fileName.substring(index,fileName.length()).toLowerCase();  

145.                        String type = null;  

146.                        for(int x=0; x

147.                            //支持的格式,才会在文件浏览器中显示  

148.                            if(endName.equals(FILE_MapTable[x][0])){  

149.                                type = FILE_MapTable[x][1];  

150.                                break;  

151.                            }  

152.       

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2