Changelog
- Feat: New
PlaybackState
added called background
. Indicates that the player is currently in the background.
- Fix: Disabled the old behavior of the player to auto resume playback if the player's
enableBackgroundPlayback
was false
and the player was in the pause
state.
- Feat: Multi-player support has been added to both iOS and tvOS.
- Feat:
FlowplayerAPI
has a new property called id: String
which can be used to identify a specific player instance.
- Feat: All
Notification
sent from the FlowplayerAPI
, FlowplayerView
and AdService
are now sending the following user info [\FlowplayerAPI.id: "<some-id>"]
which indicates the player that the notification has been sent from.
- Feat: All new UI for both iOS and tvOS demo apps showcasing new behaviors for both multi-player and background playback state.
How to auto-resume playback coming back from the background:
// FlowplayerDelegate
func player(_ player: FlowplayerAPI, didChangePlaybackState state: PlaybackState) {
print("PlaybackState changed to: \(state)")
// Current state is .playing, and previous state is .background
let wasInBackground = player.playbackStateList.prefix(2) == [
.playing,
.background
]
/// If player was paused, continue playback from the background
if wasInBackground && player.state == .pause {
player.play()
}
}
How to identify which player triggered a delegate callback:
// Players
var myPlayer: FlowplayerAPI?
var myOtherPlayer: FlowplayerAPI?
// FlowplayerDelegate
func player(player: FlowplayerAPI, didChangeState state: PlayerState) {
guard myPlayer.id == player.id else {
print("myOtherPlayer triggered this")
return
}
print("myPlayer did change state to: \(state)")
}
How to identify which player triggered a notification:
// Players
var myPlayer: FlowplayerAPI?
var myOtherPlayer: FlowplayerAPI?
// Regiter Notification
NotificationCenter.default.addObserver(
self,
selector: #selector(onReceivedState),
name: .flowplayerDidChangeState,
object: nil
)
// Notification Selector
@objc
private func onReceivedState(_ notification: Notification) {
guard
let id = notification.userInfo?[\FlowplayerAPI.id] as? String,
myPlayer.id == id
else {
print("myOtherPlayer triggered this")
return
}
guard let state = notification.object as? PlaybackState else {
return
}
print("myPlayer did change state to: \(state)")
}