nstudio / nativescript-audio

:microphone: NativeScript plugin to record and play audio :musical_note:
Other
149 stars 104 forks source link

Background Mode Audio #160

Open LucyTurtle opened 4 years ago

LucyTurtle commented 4 years ago

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>
bradmartin commented 4 years ago

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.

pabloacastillo commented 4 years ago

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

liamcharmer commented 1 year ago

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