Open coderReview opened 6 years ago
@coderReview is it resolved ?
@JijeshP not that I know of.
After beating my head against the same problem I see the issue. The project uses AVAudioSessionCategoryPlayAndRecord which is controlled by the silent switch to either play or not play. What you guys (and I) want is AVAudioSessionCategoryPlayback which plays whether or not the mute switch is on.
To fix this the project could expose a "play even if muted option" but till that happens since the .play() function doesn't set the category and it's only set on the initWithFile / initWithUrl you can init the player, change the Category then play it and it'll work.
If you need to access the native apis you might need to set that up if you haven't previously, see this https://www.npmjs.com/package/tns-platform-declarations
this.player
.initFromUrl({
audioFile: 'http://www.noiseaddicts.com/samples_1w72b820/4938.mp3', //this.sound.file,
loop: false,
completeCallback: () => {
this.isPlaying = false
this.digest()
}
})
.then(() => {
if (!this.player.isAudioPlaying()) {
const audioSession = AVAudioSession.sharedInstance();
audioSession.setCategoryError(AVAudioSessionCategoryPlayback);
this.isPlaying = true
this.player.play()
}
})
Thanks for that. I would like to see a setting for play with silent on, too.
@DanLatimer it seems not working, i don't know why, i'm using javascript but the error is the same
AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Altoparlante (type: Speaker)
To give some direction for people having issues in Nativescript 6 with background playback (i.e. when the device is locked etc), @DanLatimer solution does seem to fix this. Just make sure to add a conditional check that it is iOS, since this is platform-specific.
I've been previously setting the playback category in main.js (NS Vue, JS) without any issues, until the NS 6 update. I ended up adjusting to the given solution above, after some time troubleshooting, and got it to work again. Thanks! :)
After beating my head against the same problem I see the issue. The project uses AVAudioSessionCategoryPlayAndRecord which is controlled by the silent switch to either play or not play. What you guys (and I) want is AVAudioSessionCategoryPlayback which plays whether or not the mute switch is on.
To fix this the project could expose a "play even if muted option" but till that happens since the .play() function doesn't set the category and it's only set on the initWithFile / initWithUrl you can init the player, change the Category then play it and it'll work.
If you need to access the native apis you might need to set that up if you haven't previously, see this https://www.npmjs.com/package/tns-platform-declarations
this.player .initFromUrl({ audioFile: 'http://www.noiseaddicts.com/samples_1w72b820/4938.mp3', //this.sound.file, loop: false, completeCallback: () => { this.isPlaying = false this.digest() } }) .then(() => { if (!this.player.isAudioPlaying()) { const audioSession = AVAudioSession.sharedInstance(); audioSession.setCategoryError(AVAudioSessionCategoryPlayback); this.isPlaying = true this.player.play() } })
This fixed the issue for me, thanks :)
Audio won't play with Silent Switch on.
Error in log: