MediaPlayer的setDataSource中的IllegalArgumentException

时间:2013-05-13 13:38:41

标签: android illegalargumentexception

我正在为我的媒体播放器设置setDataSource,但是当我这样做时,我得到了IllegalArgumentException。我无法确定概率,有什么遗漏吗?

mediaPlayer = new MediaPlayer();

try{
        mediaPlayer.setDataSource(getPathName);
    }catch(IllegalArgumentException e){
        throw new RuntimeException("Illegal Argument to MediaPlayer.setDataSource", e);
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        throw new RuntimeException("Illegal State in MediaPlayer.setDataSource", e);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        throw new RuntimeException("IOException in MediaPlayer.setDataSource", e);
    }

    try{
        mediaPlayer.prepare();
    }catch(IllegalStateException e){
        throw new RuntimeException("IllegalStateException in MediaPlayer.prepare", e);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        throw new RuntimeException("IOException in MediaPlayer.prepare", e);

    }
    mediaPlayer.setOnCompletionListener(this);
}

这是我调用以返回文件名

的方法
public String getPathName(){
    String[] name = new String[2];
    String FileName;
    String FilePath;
    File sdCardRoot = Environment.getExternalStorageDirectory();
    File yourDir = new File(sdCardRoot, "/Android/data/com.voice.recording.v3/files/");

    name = yourDir.list();

    FileName = name[0];

    FilePath = yourDir.getPath() +"/" + FileName;

    return FilePath;

}

0 个答案:

没有答案