MediaPlayer : Should have subtitle controller already set: KitKat

前端 未结 5 1064
萌比男神i
萌比男神i 2020-12-23 20:34

I am having an odd issue where my audio file sometimes plays and sometimes does not play. The catch is that when it decides to not play, the DDMS gives me an:



        
5条回答
  •  盖世英雄少女心
    2020-12-23 21:06

    Its been a long time since I was working on this app. Here is what I ended up doing to get this to work. (Tested on KitKat and Lollipop). I think switching from MediaPlayer to APMediaPlayer was part of the trick.

    @Override
    public void onDestroy() {
        if(player != null) {
            player.release();
            player = null;
        }
        super.onDestroy();
    }
    
    
    @Override
    public void onStart() {
        super.onStart();
        if(player != null) {
            player.start();
        }
        else {
            player = new APMediaPlayer(this); //create new APMediaPlayer
            player.setMediaFile("Theme.mp3"); //set the file (files are in data folder)
            player.start(); //start play back
            player.setLooping(true); //restart playback end reached
            player.setVolume(1, 1); //Set left and right volumes. Range is from 0.0 to 1.0
        }
    
    }
    
    @Override
    public void onResume() {
        super.onResume();
        if(player != null) {
            player.start();
        }
    
    }
    

提交回复
热议问题