0

我有一個正確的VideoURI在Activity中播放視頻。Android:VideoView和Intent之間的區別.ACTION_VIEW

Uri videoUri = Uri.fromFile(file); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(videoUri, "video/*"); 
startActivity(intent); 

這可以在整個屏幕上播放視頻。

我也嘗試使用VideoView小部件播放此視頻,但無法加載視頻。

mVideoView = (VideoView)findViewById(R.id.video_view); 
mVideoView.setVideoURI(videoUri); 
mVideoView.requestFocus(); 
mVideoView.start(); 

該視頻文件位於sdcard/Movies/my_video.mp4;

當我運行使用VideoView的logcat的給..

W/VideoView: Unable to open content: file:///storage/emulated/0/Movies/my_video.mp4 
java.io.FileNotFoundException: /storage/emulated/0/Movies/my_video.mp4 (Permission denied) 

任何幫助將是巨大的。 謝謝。

回答

0

已解決。

代碼中沒有問題。

1)我需要手動授予應用程序訪問本地存儲的權限。 (應用程序設置)

2)接下來,我創建了一個意圖,允許訪問應用程序設置中的本地存儲。

相關問題