Note that there are some explanatory texts on larger screens.

plurals
  1. POPlay Background Audio with AVPlayer in MonoTouch?
    text
    copied!<p>Firstly, I understand this is a copy of a similar objective C based question, but it wasn't answered.</p> <p>Im using AVPlayer for the audio in my app. I have it playing audio, setting up its audio session correctly (I think, the play icon appears in the status bar when I play audio tracks within my app, and my app icon appears beside the player transport controls in the multitasking dock). However, I cannot get it to continue playing in the background when I press the Home button. The music just fades out and stops.</p> <p>I have the following key in my info.plist:</p> <pre><code>&lt;key&gt;UIBackgroundModes&lt;/key&gt; &lt;array&gt; &lt;string&gt;audio&lt;/string&gt; &lt;/array&gt; </code></pre> <p>In my class that handles playback, I have:</p> <pre><code>AVAudioSession audioSession = AVAudioSession.SharedInstance(); NSError error; audioSession.SetCategory(AVAudioSession.CategoryPlayback.ToString(),out error); audioSession.SetActive(true,out error); UIApplication.SharedApplication.BeginReceivingRemoteControlEvents(); int taskID = 0; taskID = UIApplication.SharedApplication.BeginBackgroundTask(delegate { if(taskID !=0) { UIApplication.SharedApplication.EndBackgroundTask(taskID); taskID = 0; } }); PlaylistManager = new ApolloPlaylistManager(); AudioPlayer = new AVPlayer(); </code></pre> <p>Not sure if I need that BeginBackgroundTask part, but it doesn't work if its in or out, im actually pretty sure I dont need it. Any tips at all greatly appreciated, as I've been stuck on this for a few days :-(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload