Interruption does not start back after the Track Player Reset
Hello, I have two different problems.
My scenario is the following -> user plays an audio from Spotify, Youtube etc. and then starts the app and app will trigger the sounds automatically.
- In iOS, Ducking works but after the duck the volume of the Spotify is not the same as before ( it has less volume)
- In Android, interruption works but does not start the Spotify Back.
My Implementation:
service.js
import TrackPlayer from 'react-native-track-player';
module.exports = async function () {
TrackPlayer.addEventListener('remote-play', () => TrackPlayer.play());
TrackPlayer.addEventListener('remote-pause', () => TrackPlayer.pause());
};
App.js
await TrackPlayer.setupPlayer({
autoHandleInterruptions:true,
iosCategoryOptions: [
IOSCategoryOptions.DuckOthers
]
});
await TrackPlayer.updateOptions({
capabilities: [
Capability.Play,
Capability.Pause
],
android: {
alwaysPauseOnInterruption: true,
// This is the default behavior
appKilledPlaybackBehavior: AppKilledPlaybackBehavior.ContinuePlayback,
stopForegroundGracePeriod: 2
},
icon: require("../assets/img/logo_app_rounded.png")
});
Component
const playAudio= (audioId, lat,lng) =>{
const url = BASE_URL + "/audios/" + audioId
axios.get(url).then((response) => {
let audioData =response.data
TrackPlayer.add([{
url: audioData.url,
title: audioData.name,
artist: "Artist"
}]).then(() => {
TrackPlayer.play().then(() =>{
console.log("Playing")
})
TrackPlayer.addEventListener(Event.PlaybackQueueEnded, () => {
TrackPlayer.reset().then(()=> console.log("Track Player Reset"))
})
})
})
}
for ios you are not alone. though im not aware of a solution. for android i believe its not supposed to bring other media playback back - RNTP is a music player, not a short video player. when using system managed audio focus it requests AUDIOFOCUS_GAIN not AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE so audiofocus is not granted back to the previous owner. This is also true for any other music players where pausing one doesnt automatically restore playback from another. youre always welcome to fork and change the audiofocus gain type of course.
https://developer.android.com/media/optimize/audio-focus#audio-focus-change
@lovegaoshi thank you! Do you know which part of the code should I change in order to get this functionality?
u can try replacing AUDIOFOCUS_GAIN to AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE in https://github.com/doublesymmetry/KotlinAudio and see if it works
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.