码迷,mamicode.com
首页 > 其他好文 > 详细

利用VideoView播放视频

时间:2017-05-02 09:52:37      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:lis   article   pos   storage   oncreate   position   min   word   end   

package com.qianhua.ui;
002  
003 import android.app.Activity;
004 import android.content.Intent;
005 import android.media.MediaPlayer;
006 import android.net.Uri;
007 import android.os.Bundle;
008 import android.os.Environment;
009 import android.widget.MediaController;
010 import android.widget.MediaController.MediaPlayerControl;
011 import android.widget.VideoView;
012  
013 import com.qianhua.R;
014  
015 public class VideoActivity extends Activity implements MediaPlayerControl {
016     VideoView videoView;
017  
018     @Override
019     protected void onCreate(Bundle savedInstanceState) {
020         // TODO Auto-generated method stub
021         super.onCreate(savedInstanceState);
022         setContentView(R.layout.activity_video);
023         videoView = (VideoView) findViewById(R.id.video_view);
024         if (Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) {
025             // 可播放格式3.3gp  m.mp4 a.avi  ;不可播放格式f.flv
026             videoView.setVideoURI(Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/"+"mm.mp4"));
027             MediaController mediaController = new MediaController(this);
028             videoView.setMediaController(mediaController);
029             videoView.start();
030             videoView.requestFocus();
031              
032             videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
033                  
034                 @Override
035                 public void onCompletion(MediaPlayer arg0) {
036                     // TODO Auto-generated method stub
037                     Intent intent=new Intent(VideoActivity.this,PersonLoginUI.class);
038                     startActivity(intent); 
039                 }
040             });
041         }
042  
043     }
044  
045     @Override
046     public boolean canPause() {
047         // TODO Auto-generated method stub
048         videoView.canPause();
049         return false;
050     }
051  
052     @Override
053     public boolean canSeekBackward() {
054         // TODO Auto-generated method stub
055         return false;
056     }
057  
058     @Override
059     public boolean canSeekForward() {
060         // TODO Auto-generated method stub
061         return false;
062     }
063  
064     @Override
065     public int getBufferPercentage() {
066         // TODO Auto-generated method stub
067         return 0;
068     }
069  
070     @Override
071     public int getCurrentPosition() {
072         // TODO Auto-generated method stub
073         return 0;
074     }
075  
076     @Override
077     public int getDuration() {
078         // TODO Auto-generated method stub
079         return 0;
080     }
081  
082     @Override
083     public boolean isPlaying() {
084         // TODO Auto-generated method stub
085         return false;
086     }
087  
088     @Override
089     public void pause() {
090         // TODO Auto-generated method stub
091         if(videoView.isPlaying()){
092             videoView.pause();
093         }
094  
095     }
096  
097     @Override
098     public void seekTo(int arg0) {
099         // TODO Auto-generated method stub
100         videoView.seekTo(arg0);
101  
102     }
103  
104     @Override
105     public void start() {
106         // TODO Auto-generated method stub
107         if (!videoView.isPlaying()) {
108             videoView.start();
109         }
110  
111     }
112  
113 }

利用VideoView播放视频

标签:lis   article   pos   storage   oncreate   position   min   word   end   

原文地址:http://www.cnblogs.com/gccbuaa/p/6794522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!