1. 程式人生 > >Android 利用傳送Intent播放本地視訊和網路視訊

Android 利用傳送Intent播放本地視訊和網路視訊

Android中除了利用VideoView、Mediaplayer播放視訊檔案外,還可以用傳送Intent來呼叫視訊播放模組。

方法如下:

1.播放本地視訊

  Intent intent = new Intent(Intent.ACTION_VIEW);

        String type = "video/mp4";
        Uri uri = Uri.parse("file:///sdcard/test.mp4");
        intent.setDataAndType(uri, type);
        startActivity(intent);

2.播放網路視訊

  Intent intent = new Intent(Intent.ACTION_VIEW);

        String type = "video/* ";

   Uri uri = Uri.parse("http://forum.ea3w.com/coll_ea3w/attach/2008_10/12237832415.3gp");
        intent.setDataAndType(uri, type);
        startActivity(intent);

注意紅色部分,如果不設定type的話,這樣寫:

  Intent intent = new Intent(Intent.ACTION_VIEW);

  Uri uri = Uri.parse("http://forum.ea3w.com/coll_ea3w/attach/2008_10/12237832415.3gp");
       intent.setData (uri);
       startActivity(intent);  

這樣會預設用瀏覽器開啟這個URL!