timer - How to stop media player from another activity in android programamtically? -


hi trying use media player in app , have trying stop media player other activity coding following:

firstactivity:

  public void stop() {        if (playpause == false) {              control.setbackgroundresource(r.drawable.play);              mediaplayer.stop();             new player().cancel(true);             media.stop();             media.reset();             mediaplayer.reset();             if (mediaplayer.isplaying())                 mediaplayer.stop();             mediaplayer.reset();             media.stop();              playpause = true;         } else {             control.setbackgroundresource(r.drawable.pause);             if (intialstage) {                 new player()                         .execute(url);             } else {                 if (!mediaplayer.isplaying())                     mediaplayer.start();             }             playpause = false;         }      } 

secondactivity:

have stop media player after timer end:

 @override         public void onfinish() {              textviewtime.settext(hmstimeformatter(timecountinmilliseconds));             // call initialize progress bar values             setprogressbarvalues();             // hiding reset icon             imageviewreset.setvisibility(view.gone);             // changing stop icon start icon             imageviewstartstop.setimageresource(r.drawable.icon_start);             // making edit text editable             edittextminute.setenabled(true);             // changing timer status stopped             timerstatus = timerstatus.stopped;           mainactivity main = new mainactivity();             main.stop();         }      }.start();     countdowntimer.start(); } 

the above coding shows error:

 java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.imageview.setbackgroundresource(int)' on null object reference                                                                          @ com.digitamatix.mukilfm.mainactivity.stop(mainactivity.java:549) 

i have stop media player in first activity please me on coding fix issues

see have started activity startactivityforresult . onactivityresult result.

startactivityforresult(activity1.createintent(this), 1001);   //handle callback result @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     if (resultcode == result_ok) {         if (requestcode == 1001) {          }     }  } 

below code call in next activity want callback , finish activity. can pass value intent.

 intent intent = new intent();  setresult(result_ok, intent);  finish(); 

so, per requirement can use this. stop media player. other option local broadcast too. hope you.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -