nativescript-audio icon indicating copy to clipboard operation
nativescript-audio copied to clipboard

Background Mode Audio

Open LucyTurtle opened this issue 5 years ago • 3 comments

Hello,

Background mode audio, even after setting a category is not working for me for either iOS or Android.

const playerOptions = {
    	audioFile: '~/audio/'+info.audio+".png",
    	loop: true,
        autoplay: true
  	};
  	
  	player
	    .initFromFile(playerOptions)
        .then( function() {
              if(player.ios){
                  const audioSession = AVAudioSession.sharedInstance();
                  audioSession.setCategoryError( AVAudioSessionCategoryPlayback );
                  player.play();
              }
              
        })
		.catch(function(err) {
		    console.log('something went wrong...', err);
		});
<key>UIBackgroundModes</key>
<array>
	<string>audio</string>
	<string>fetch</string>
</array>

LucyTurtle avatar Dec 11 '19 20:12 LucyTurtle

It's a bit different approach to do background audio like I think you're looking for entirely. And you'll actually need to use a different native player on iOS for streaming that won't block main thread. I've still not had any free time or work requirements to finish any work on this. I had this working in a private project years ago but being private couldn't OSS it at the time. I'd still like to find time to update the plugin here and add these options but I'm low on time unfortunately.

bradmartin avatar Dec 19 '19 04:12 bradmartin

Hi! I did some changes to the ios version of the library to add this feature (audio streaming) and have a working version on my app. (Migrated from AVAudioPlayer to AVPlayer)

You can check the changes in the ios/player.ts https://github.com/mehyaa/nativescript-audioplay/pull/2

pabloacastillo avatar Jan 27 '20 20:01 pabloacastillo

Was there any update with this at all? Or any further directions for both iOS and Android?

liamcharmer avatar Mar 02 '23 01:03 liamcharmer