0

我在 Nexus 7 上运行我的应用程序时遇到了一些麻烦,我想知道这个设备是否有某种怪癖可以解决,因为它在 HTC Wildfire S 上运行良好。

我正在尝试将midi文件写入SD卡,然后将相同的midi文件调用到android MediaPlayer中。问题是,该文件仅在我关闭应用程序后才写入,这对我的目的没有好处。

在 Wildfire 上,它会实时写入文件,然后立即将其调用到媒体播放器中,没有任何问题。

这是代码

try{
         mf.writeToFile ("/mnt/sdcard/temp.mid");

         }
         catch (IOException e){
         Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
         }





    String PATH_TO_FILE = "/mnt/sdcard/temp.mid";    
    mediaPlayer = new  MediaPlayer();

    try {
   mediaPlayer.setDataSource(PATH_TO_FILE);
   mediaPlayer.prepare(); 
4

1 回答 1

1

do not hard code the path.

Instead try this,

 String PATH_TO_FILE =   Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"temp.mid";

the same way for writetoFile() also.

于 2013-01-18T13:12:33.323 回答