I am new so excuse me if I dont ask a question right or post enough information.
I am new to creating mobile applications and i am using Xamarin.Forms to create a custom view. with this view I am using an Android ViewRenderer to play audio/video with built in android MediaPlayer/VideoView.
pretty much the exact same thing as the android renderer posted and accepted as the answer for Renderer I copied and is working
My issue is when the video starts and you click the homepage/back button the audio continues playing for a few seconds and then stops. I want to audio to stop immediately.
Methods I have tried:
In my ViewRenderer I have attempted to override SurfaceDestroyed to call player.stop(). This has not worked, no errors or anything just audio continues like this code doesnt exist. Audio stops after about 3-5 seconds.
In the ViewRenderer I have attempted to use the Control.SystemUiVisibilityChange event to call player.stop(). No errors or anything. Audio continues for 3-5 seconds.
I am unable to pass the player instance to the main activity onPause() method as I am to new to Xamarin.Forms and android ViewRenderers to understand how to. Possibly calling this player.stop() on the onPause() method will work but I cant find how to do this. Can anyone assist? I have searched many forums for weeks and have finally given up to post a question.
For back button, you simply need to override
OnBackButtonPressedof your currentXamarin.Forms' page:For home button, I referred to this thread and made a Xamarin version of
HomeWatcherout of Jack's answer:And use it in the
VideoViewRenderer(StartWatch()when video start play,StopWatch()when the videoview is cleaned):