Fix emoji sound playback

This commit is contained in:
Ilya Laktyushin 2020-10-27 07:08:47 +04:00
parent 9f1f1b49e7
commit 65d707fa4f

View File

@ -1218,7 +1218,9 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
} else if let _ = self.emojiFile { } else if let _ = self.emojiFile {
if let animationNode = self.animationNode as? AnimatedStickerNode { if let animationNode = self.animationNode as? AnimatedStickerNode {
var startTime: Signal<Double, NoError> var startTime: Signal<Double, NoError>
if animationNode.playIfNeeded() { var shouldPlay = false
if !animationNode.isPlaying {
shouldPlay = true
startTime = .single(0.0) startTime = .single(0.0)
} else { } else {
startTime = animationNode.status startTime = animationNode.status
@ -1238,6 +1240,9 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
if let text = self.item?.message.text, let firstScalar = text.unicodeScalars.first { if let text = self.item?.message.text, let firstScalar = text.unicodeScalars.first {
if beatingHearts.contains(firstScalar.value) || firstScalar.value == peach { if beatingHearts.contains(firstScalar.value) || firstScalar.value == peach {
if shouldPlay {
animationNode.play()
}
return .optionalAction({ return .optionalAction({
let _ = startTime.start(next: { [weak self] time in let _ = startTime.start(next: { [weak self] time in
guard let strongSelf = self else { guard let strongSelf = self else {
@ -1263,19 +1268,24 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
}) })
} else { } else {
return .optionalAction({ return .optionalAction({
let _ = (appConfiguration if shouldPlay {
|> deliverOnMainQueue).start(next: { [weak self] appConfiguration in let _ = (appConfiguration
let emojiSounds = AnimatedEmojiSoundsConfiguration.with(appConfiguration: appConfiguration, account: item.context.account) |> deliverOnMainQueue).start(next: { [weak self] appConfiguration in
for (emoji, file) in emojiSounds.sounds { let emojiSounds = AnimatedEmojiSoundsConfiguration.with(appConfiguration: appConfiguration, account: item.context.account)
if emoji.unicodeScalars.first == firstScalar { for (emoji, file) in emojiSounds.sounds {
let mediaManager = item.context.sharedContext.mediaManager if emoji.unicodeScalars.first == firstScalar {
let mediaPlayer = MediaPlayer(audioSessionManager: mediaManager.audioSession, postbox: item.context.account.postbox, resourceReference: .standalone(resource: file.resource), streamable: .none, video: false, preferSoftwareDecoding: false, enableSound: true, fetchAutomatically: true) let mediaManager = item.context.sharedContext.mediaManager
mediaPlayer.togglePlayPause() let mediaPlayer = MediaPlayer(audioSessionManager: mediaManager.audioSession, postbox: item.context.account.postbox, resourceReference: .standalone(resource: file.resource), streamable: .none, video: false, preferSoftwareDecoding: false, enableSound: true, fetchAutomatically: true)
self?.mediaPlayer = mediaPlayer mediaPlayer.togglePlayPause()
break self?.mediaPlayer = mediaPlayer
animationNode.play()
break
}
} }
} })
}) }
}) })
} }
} }