如何調用系統自帶的播放器播放視訊呢?
最近在android開發學習中,了解到程式和程式之間的界限不像其他其它平台那樣明顯
當我寫一個程式,在下載下傳好自定義的音頻或視訊檔案後,能不能在程式中啟動系統自帶的音視訊播放器進行播放呢?我是不是可以構造個合理的intent,給出檔案路徑,讓它去啟動系統已有的播放器?
我的目的是,調用系統預設的音視訊播放器,就可以免去自己另外費時間開發了
------解決方案--------------------
public Intent getMediaFileIntent(File audioFile)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("oneshot", 0);
intent.putExtra("configchange", 0);
Uri uri = Uri.fromFile(audioFile);
String filename = audioFile.getName();
String suffixName = filename.substring(filename.lastIndexOf("."), filename.length());
intent.setDataAndType(uri, DT.get(suffixName));
return intent;
}
File audioFile = new File("/mnt/sdcard/files/Hwllo.mp4");
------解決方案--------------------
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videourl)); startActivity(intent); 應該能播放視訊檔案。
------解決方案--------------------
引用:非常感謝!
我使用了這種方法,成功用預設播放器播放視訊
但存在個問題,我第二次運作播放時,播放器會提示是否跳轉到上次播放的位置繼續播放,而這個功能是我不需要的,有辦法定制預設播放器的功能嗎?
引用:Java code?1234567891011121314public Intent getMediaFileIntent(……
恩,不好意思,上次沒有把完整的代碼貼全,但有幸的是你竟然成功運作了;
我再貼一下完整的代碼:
private Intent getVideoFileIntent(File videoFile)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("oneshot", 0);
intent.putExtra("configchange", 0);
Uri uri = Uri.fromFile(videoFile);
intent.setDataAndType(uri, "video/*");
return intent;
}
注意:這段代碼和上次的是一樣的。
至于你說定制,我沒有做過,我想提示你是否繼續上次播放,應該是播放器軟體本身的一種功能,理論上應該是不能定制的。
希望你可以找到好辦法。