Skip to content

Commit

Permalink
iOS fix crash when playing item if player is already open, persist pl…
Browse files Browse the repository at this point in the history
…ayback rate between playbacks, version bump 0.9.42
  • Loading branch information
advplyr committed Apr 23, 2022
1 parent a0a7fd1 commit 729e959
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand All @@ -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 = "";
Expand Down
3 changes: 2 additions & 1 deletion ios/App/App/plugins/AbsAudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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())
Expand Down
14 changes: 7 additions & 7 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions ios/App/Shared/player/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions ios/App/Shared/player/PlayerHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 729e959

Please sign in to comment.