Audio is not playing after stop serviec in Media player

℡╲_俬逩灬. 提交于 2019-12-02 07:54:12

You should use startService() to run your service and communicate with it using a Binder. It is not a regualr object, you need the Android OS to be made aware of it and you need to behave as it expects you to.

http://developer.android.com/reference/android/app/Service.html

You shouldn't create an instance yourself and shouldn't call its methods directly.

Chintan Khetiya

i got solution after 5 min and i have done silly mistake.I was forgot to add player = null;

This whole code is working perfectly without any error but one of the developer (selalerer) also suggest me to Refer this. I have implement that way also and that is also working perfectly.

public void stop_audio() {
     try {
         if (player != null) {
             if (player.isPlaying()) {
                 ac.play_pause.setText("Play");
                 player.stop();
                 player.release();
                 player = null; // forgot this statement  

             } else {
                 ac.play_pause.setText("Play");
                 player.release();
                 player = null; // forgot this statement  

             }
         }
     } catch (Exception e) {
         // TODO: handle exception
         Log.e("stop_service", "" + e);
     }
 }
AnilPatel

you try stop after for play of audio

try {

    player.reset();
    player.setDataSource(url);
    player.prepare();
    player.seekTo(0);

} catch (IllegalArgumentException e1) {
    e1.printStackTrace();
} catch (SecurityException e1) {
    e1.printStackTrace();
} catch (IllegalStateException e1) {
    e1.printStackTrace();
} catch (IOException e1) {
    e1.printStackTrace();
}
player.start();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!