利用VideoView播放视频

来源:互联网 发布:八宝茶的软件 编辑:程序博客网 时间:2024/09/21 08:57

利用VideoView播放视频简单代码

[1].[代码] [Java]代码 跳至 [1]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
packagecom.qianhua.ui;
 
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.media.MediaPlayer;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.os.Environment;
importandroid.widget.MediaController;
importandroid.widget.MediaController.MediaPlayerControl;
importandroid.widget.VideoView;
 
importcom.qianhua.R;
 
publicclass VideoActivity extendsActivity implementsMediaPlayerControl {
    VideoView videoView;
 
    @Override
    protectedvoid onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        videoView = (VideoView) findViewById(R.id.video_view);
        if(Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) {
            // 可播放格式3.3gp  m.mp4 a.avi  ;不可播放格式f.flv
            videoView.setVideoURI(Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/"+"mm.mp4"));
            MediaController mediaController = newMediaController(this);
            videoView.setMediaController(mediaController);
            videoView.start();
            videoView.requestFocus();
             
            videoView.setOnCompletionListener(newMediaPlayer.OnCompletionListener() {
                 
                @Override
                publicvoid onCompletion(MediaPlayer arg0) {
                    // TODO Auto-generated method stub
                    Intent intent=newIntent(VideoActivity.this,PersonLoginUI.class);
                    startActivity(intent); 
                }
            });
        }
 
    }
 
    @Override
    publicboolean canPause() {
        // TODO Auto-generated method stub
        videoView.canPause();
        returnfalse;
    }
 
    @Override
    publicboolean canSeekBackward() {
        // TODO Auto-generated method stub
        returnfalse;
    }
 
    @Override
    publicboolean canSeekForward() {
        // TODO Auto-generated method stub
        returnfalse;
    }
 
    @Override
    publicint getBufferPercentage() {
        // TODO Auto-generated method stub
        return0;
    }
 
    @Override
    publicint getCurrentPosition() {
        // TODO Auto-generated method stub
        return0;
    }
 
    @Override
    publicint getDuration() {
        // TODO Auto-generated method stub
        return0;
    }
 
    @Override
    publicboolean isPlaying() {
        // TODO Auto-generated method stub
        returnfalse;
    }
 
    @Override
    publicvoid pause() {
        // TODO Auto-generated method stub
        if(videoView.isPlaying()){
            videoView.pause();
        }
 
    }
 
    @Override
    publicvoid seekTo(intarg0) {
        // TODO Auto-generated method stub
        videoView.seekTo(arg0);
 
    }
 
    @Override
    publicvoid start() {
        // TODO Auto-generated method stub
        if(!videoView.isPlaying()) {
            videoView.start();
        }
 
    }
 
}

0 0