IllegalArgumentException in setDataSource for MediaPlayer

久未见 提交于 2021-01-28 04:46:50

问题


I'm trying to setDataSource for my mediaplayer but when I do that I get IllegalArgumentException. I couldn't identify the prob, is there anything missing?

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);
}

this is a method that I call to return the file name

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;

}

来源:https://stackoverflow.com/questions/16523521/illegalargumentexception-in-setdatasource-for-mediaplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!