From 729e959506f52514d2c7b7ca189368e811343693 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 23 Apr 2022 15:40:18 -0500 Subject: [PATCH] iOS fix crash when playing item if player is already open, persist playback rate between playbacks, version bump 0.9.42 --- ios/App/App.xcodeproj/project.pbxproj | 8 ++++---- ios/App/App/plugins/AbsAudioPlayer.swift | 3 ++- ios/App/Podfile | 14 +++++++------- ios/App/Shared/player/AudioPlayer.swift | 9 ++++++--- ios/App/Shared/player/PlayerHandler.swift | 4 ++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/ios/App/App.xcodeproj/project.pbxproj b/ios/App/App.xcodeproj/project.pbxproj index 2b96344c..f69cd213 100644 --- a/ios/App/App.xcodeproj/project.pbxproj +++ b/ios/App/App.xcodeproj/project.pbxproj @@ -455,12 +455,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = Icons; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_TEAM = 7UFJ7D8V6A; INFOPLIST_FILE = App/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 0.9.41; + MARKETING_VERSION = 0.9.42; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = com.audiobookshelf.app.development; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -479,12 +479,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = Icons; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_TEAM = 7UFJ7D8V6A; INFOPLIST_FILE = App/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 0.9.41; + MARKETING_VERSION = 0.9.42; PRODUCT_BUNDLE_IDENTIFIER = com.audiobookshelf.app; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = ""; diff --git a/ios/App/App/plugins/AbsAudioPlayer.swift b/ios/App/App/plugins/AbsAudioPlayer.swift index 781baf2b..eff135e0 100644 --- a/ios/App/App/plugins/AbsAudioPlayer.swift +++ b/ios/App/App/plugins/AbsAudioPlayer.swift @@ -22,6 +22,7 @@ public class AbsAudioPlayer: CAPPlugin { let libraryItemId = call.getString("libraryItemId") let episodeId = call.getString("episodeId") let playWhenReady = call.getBool("playWhenReady", true) + let playbackRate = call.getFloat("playbackRate", 1) if libraryItemId == nil { NSLog("provide library item id") @@ -34,7 +35,7 @@ public class AbsAudioPlayer: CAPPlugin { sendPrepareMetadataEvent(itemId: libraryItemId!, playWhenReady: playWhenReady) ApiClient.startPlaybackSession(libraryItemId: libraryItemId!, episodeId: episodeId) { session in - PlayerHandler.startPlayback(session: session, playWhenReady: playWhenReady) + PlayerHandler.startPlayback(session: session, playWhenReady: playWhenReady, playbackRate: playbackRate) do { self.sendPlaybackSession(session: try session.asDictionary()) diff --git a/ios/App/Podfile b/ios/App/Podfile index 44119188..584acebb 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -9,13 +9,13 @@ install! 'cocoapods', :disable_input_output_paths => true def capacitor_pods pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' - pod 'CapacitorApp', :path => '..\..\node_modules\@capacitor\app' - pod 'CapacitorDialog', :path => '..\..\node_modules\@capacitor\dialog' - pod 'CapacitorHaptics', :path => '..\..\node_modules\@capacitor\haptics' - pod 'CapacitorNetwork', :path => '..\..\node_modules\@capacitor\network' - pod 'CapacitorStatusBar', :path => '..\..\node_modules\@capacitor\status-bar' - pod 'CapacitorStorage', :path => '..\..\node_modules\@capacitor\storage' - pod 'RobingenzCapacitorAppUpdate', :path => '..\..\node_modules\@robingenz\capacitor-app-update' + pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app' + pod 'CapacitorDialog', :path => '../../node_modules/@capacitor/dialog' + pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics' + pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network' + pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar' + pod 'CapacitorStorage', :path => '../../node_modules/@capacitor/storage' + pod 'RobingenzCapacitorAppUpdate', :path => '../../node_modules/@robingenz/capacitor-app-update' end target 'App' do diff --git a/ios/App/Shared/player/AudioPlayer.swift b/ios/App/Shared/player/AudioPlayer.swift index 5b87ea61..0bd7270c 100644 --- a/ios/App/Shared/player/AudioPlayer.swift +++ b/ios/App/Shared/player/AudioPlayer.swift @@ -22,18 +22,21 @@ class AudioPlayer: NSObject { private var playerItemContext = 0 private var playWhenReady: Bool + private var initialPlaybackRate: Float private var audioPlayer: AVPlayer private var playbackSession: PlaybackSession private var activeAudioTrack: AudioTrack // MARK: - Constructor - init(playbackSession: PlaybackSession, playWhenReady: Bool = false) { + init(playbackSession: PlaybackSession, playWhenReady: Bool = false, playbackRate: Float = 1) { self.playWhenReady = playWhenReady + self.initialPlaybackRate = playbackRate self.audioPlayer = AVPlayer() self.playbackSession = playbackSession self.status = -1 self.rate = 0.0 + self.tmpRate = playbackRate if playbackSession.audioTracks.count != 1 || playbackSession.audioTracks[0].mimeType != "application/vnd.apple.mpegurl" { NSLog("The player only support HLS streams right now") @@ -74,9 +77,9 @@ class AudioPlayer: NSObject { print(error) } - DispatchQueue.main.sync { +// DispatchQueue.main.sync { UIApplication.shared.endReceivingRemoteControlEvents() - } +// } NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.closed.rawValue), object: nil) } diff --git a/ios/App/Shared/player/PlayerHandler.swift b/ios/App/Shared/player/PlayerHandler.swift index 0788597b..c2009e7b 100644 --- a/ios/App/Shared/player/PlayerHandler.swift +++ b/ios/App/Shared/player/PlayerHandler.swift @@ -14,7 +14,7 @@ class PlayerHandler { private static var listeningTimePassedSinceLastSync = 0.0 - public static func startPlayback(session: PlaybackSession, playWhenReady: Bool) { + public static func startPlayback(session: PlaybackSession, playWhenReady: Bool, playbackRate: Float) { if player != nil { player?.destroy() player = nil @@ -23,7 +23,7 @@ class PlayerHandler { NowPlayingInfo.setSessionMetadata(metadata: NowPlayingMetadata(id: session.id, itemId: session.libraryItemId!, artworkUrl: session.coverPath, title: session.displayTitle ?? "Unknown title", author: session.displayAuthor, series: nil)) self.session = session - player = AudioPlayer(playbackSession: session, playWhenReady: playWhenReady) + player = AudioPlayer(playbackSession: session, playWhenReady: playWhenReady, playbackRate: playbackRate) // DispatchQueue.main.sync { timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in