Android開發:該視訊無法播放
阿新 • • 發佈:2019-01-22
我想要在播放器中播放一個名為"南征北戰-我的天空.mp4"的視訊,其路徑是"/storage/emulated/0/netease/cloudmusic/南征北戰-我的天空.mp4",但是我最開始在安卓原始碼中寫的路徑如下:
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/storage/emulated/0/netease/cloudmusic/MV/南征北戰-我的天空.mp4";
結果執行起來以後提示該視訊無法播放,後來列印了一下path,才知道 Environment.getExternalStorageDirectory().getAbsolutePath() 得到的路徑是/storage/emulated/0/,而不是真正的根目錄。
修改後的程式碼如下:
public class MainActivity extends AppCompatActivity { private VideoView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); videoView = (VideoView) findViewById(R.id.viedoview); String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/netease/cloudmusic/MV/南征北戰-我的天空.mp4"; File file = new File(path); /** * local vedio player */ if(file.exists()) { videoView.setVideoPath(path); } else { Log.d("IO", "file doesn't exist"); } /** * remote vedio player */ //videoView.setVideoURI(Uri.parse("")); MediaController mediaController=new MediaController(this); /** * bind mediaController and videoView */ videoView.setMediaController(mediaController); mediaController.setMediaPlayer(videoView); } }