How to attach MediaPlayer with SurfaceView in android?

前端 未结 2 1938
悲哀的现实
悲哀的现实 2020-12-13 21:51

I\'m building video player with android media player object. i\'m able to hear the audio but the video does not appear on surfaceView. here is my code

pub         


        
2条回答
  •  别那么骄傲
    2020-12-13 22:21

    It is not working for me, throwing error illegal state exception in surfaceCreated() method at line mp.setDisplay(holder);

    Declare mp.setDisplay(holder) as given below :

    @Override
    public void surfaceCreated(SurfaceHolder holder) 
    {  
        mediaPlayer.setDataSource(this,uri);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.prepare(); 
        mp.setDisplay(holder);
        mp.start;
    }
    

提交回复
热议问题