2012-03-06 186 views

回答

2
video_player_view.xml 

<?xml version="1.0" encoding="utf-8"?> 
<VideoView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/VideoPlayerView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 


Java code: 

public class VideoPlayerActivity extends Activity { 


    /** Called when the activity is first created. */ 

    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.video_player_view); 


     String video_file_path = ?;//give the path of your video 

     VideoView video_view = (VideoView) this.findViewById(R.id.VideoPlayerView); 
     MediaController mc = new MediaController(this); 
     video_view.setMediaController(mc); 
     video_view.setVideoPath(video_file_path); 
     video_view.requestFocus(); 

     // start video 
     video_view.start(); 

     video_view.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 


      public void onCompletion(MediaPlayer mp) { 
       endActivity(); 
      } 
    }); 



    } 
    public void endActivity() { 
     this.finish(); 
    } 

} 
1

你爲什麼使用這段代碼?

Intent tostart = new Intent(Intent.ACTION_VIEW); 
startActivity(tostart); 


如果沒有必要然後將其刪除的視頻將有聲播放。否則,請寫下你真正想要做的視頻播放。