adding some random optimizations to make sure player stops on second tap and also the player plays quicker
This commit is contained in:
@@ -93,19 +93,20 @@ struct CircleGridView: View {
|
|||||||
.id(value) // id for scrollviewreader
|
.id(value) // id for scrollviewreader
|
||||||
.frame(height: Self.size)
|
.frame(height: Self.size)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
withAnimation {
|
// clearing the player to make room for this friend's convo or to deselect this user
|
||||||
// if user had previously selected user, put nil as a toggle
|
self.queuePlayer.removeAllItems()
|
||||||
if self.selectedFriendIndex == value {
|
|
||||||
self.selectedFriendIndex = nil
|
// if user had previously selected user, put nil as a toggle
|
||||||
} else {
|
if self.selectedFriendIndex == value {
|
||||||
self.selectedFriendIndex = value
|
self.selectedFriendIndex = nil
|
||||||
}
|
return
|
||||||
|
} else {
|
||||||
|
self.selectedFriendIndex = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: OPTIMIZATION...buffer and load all AVAssets to create AVPlayerItems before a tap happens...but this can also cause load in background if user is not playing a message right now...this isn't an optimization of the data/firestore but rather the player
|
// TODO: OPTIMIZATION...buffer and load all AVAssets to create AVPlayerItems before a tap happens...but this can also cause load in background if user is not playing a message right now...this isn't an optimization of the data/firestore but rather the player
|
||||||
|
|
||||||
// clearing the player to make room for this friend's convo
|
|
||||||
self.queuePlayer.removeAllItems()
|
|
||||||
|
|
||||||
// I want to play the last x messages if I was the receiver
|
// I want to play the last x messages if I was the receiver
|
||||||
// ["sarth": [me, me]] -> play nothing
|
// ["sarth": [me, me]] -> play nothing
|
||||||
@@ -129,21 +130,22 @@ struct CircleGridView: View {
|
|||||||
|
|
||||||
// only add to queue if we can convert the database url to a valid url here
|
// only add to queue if we can convert the database url to a valid url here
|
||||||
if let audioUrl = URL(string: message.audioDataUrl) {
|
if let audioUrl = URL(string: message.audioDataUrl) {
|
||||||
|
print("going to add this message to queue player \(audioUrl)")
|
||||||
let playerMessage: AVPlayerItem = AVPlayerItem(url: audioUrl)
|
let playerMessage: AVPlayerItem = AVPlayerItem(url: audioUrl)
|
||||||
AVPlayerItems.append(playerMessage)
|
AVPlayerItems.append(playerMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// reverse audiourls again as we want them in order of time
|
|
||||||
AVPlayerItems = AVPlayerItems.reversed()
|
|
||||||
|
|
||||||
// start playing if there are messages to listen to
|
// start playing if there are messages to listen to
|
||||||
if AVPlayerItems.count > 0 {
|
if AVPlayerItems.count > 0 {
|
||||||
print("have message urls that we will start listening to\(AVPlayerItems)")
|
print("have message urls that we will start listening to\(AVPlayerItems)")
|
||||||
|
|
||||||
queuePlayer = AVQueuePlayer(items: AVPlayerItems)
|
queuePlayer = AVQueuePlayer(items: AVPlayerItems)
|
||||||
|
|
||||||
queuePlayer.play()
|
// TODO: make sure these options are viable for different scenarios
|
||||||
|
queuePlayer.automaticallyWaitsToMinimizeStalling = false
|
||||||
|
queuePlayer.playImmediately(atRate: 1)
|
||||||
|
// queuePlayer.play()
|
||||||
|
|
||||||
|
|
||||||
// update the listencount and firstlistentimestamp of those messages in firestore
|
// update the listencount and firstlistentimestamp of those messages in firestore
|
||||||
|
|||||||
Reference in New Issue
Block a user