我对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();
}
}提前谢谢!!
发布于 2014-02-11 12:08:24
若要获取原始资源的InputStream,请使用openRawResource(int)。
可能还可以使用MediaPlayer.create(Context,int)直接创建具有给定资源标识符的MediaPlayer。
https://stackoverflow.com/questions/21699737
复制相似问题