Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android系統教程 >> Android開發教程 >> Android VideoView播放視頻

Android VideoView播放視頻

編輯:Android開發教程

Android 利用自帶VideoView控件播放視頻

Activity

public class Activity01 extends Activity     
{     
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState)     
    {     
        super.onCreate(savedInstanceState);     

        setContentView(R.layout.main);     


        final VideoView videoView = (VideoView) findViewById(R.id.VideoView01);     

        Button PauseButton = (Button) this.findViewById(R.id.PauseButton);     
        Button LoadButton = (Button) this.findViewById(R.id.LoadButton);     
        Button PlayButton = (Button) this.findViewById(R.id.PlayButton);     

        // load     
        LoadButton.setOnClickListener(new OnClickListener() {     
            public void onClick(View arg0)     
            {     
//              videoView.setVideoPath("/sdcard/test.mp4");     
                videoView.setVideoPath("android.resource://com.homer/"+R.raw.china);     
                videoView.setMediaController(new MediaController(Activity01.this));     
                videoView.requestFocus();     
            }     
        });

        // play
        PlayButton.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0)
            {
                videoView.start();
            }
        });

        // pause
        PauseButton.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0)
            {
                videoView.pause();
            }     
        });
    }
}

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved