Android ENOENT警告

时间:2014-02-11 10:49:59

标签: android uri android-mediaplayer fileinputstream

我是Android新手试图从开源片段制作自定义视频控制器,我添加了评论,我认为有必要更好地理解代码,希望它会有所帮助

    public void playVideo(){
    if(videoview.isPlaying()){
        videoview.stopPlayback();
    }
    try {
        player.setAudioStreamType(AudioManager.STREAM_MUSIC);
        File file = new File(path);//path is a string
        FileInputStream inputStream = new FileInputStream(file);//log says warning is here
        player.setDataSource(inputStream.getFD());
        inputStream.close();
        player.setOnPreparedListener(this);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

提前致谢!!

1 个答案:

答案 0 :(得分:0)

要获取原始资源的InputStream,请使用openRawResource(int)

您可以使用MediaPlayer.create(Context,int)直接创建具有给定资源标识符的MediaPlayer