Question

I am new to android trying to make a custom video controller from an opensource snippet, i have added comments where i thought were necessary for understanding the code a little better, hope it will be helpfull

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

Thanks in advance!!

Était-ce utile?

La solution

To get an InputStream for a raw resource, use openRawResource(int).

Possibly you could also use MediaPlayer.create(Context,int) to directly create a MediaPlayer with a given resource identifier.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top