Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Stopping an action when leaving an Activity.

$
0
0

I want a music player to stop playing when the user leaves the activity they start it from (ex. they can only listen to the music player if they are on the page with the controls).

The way I figured I should do this is to override the onDestroy() method and tell it to Stop the music play (if it is currently playing), then dispose of the MediaPlayer. Here's what it looks like:

Private override onDestroy () {
     if (mediaPlayer.isPlaying) {
          mediaPlayer.Stop ();
     }

     mediaPlayer.Dispose ();
}

When I start up the music player on a build and try to navigate back the stream will stop playing, but before I can load up the menu page it errors out and force closes. I am 98% sure I did this the wrong way. Any insight?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>