mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-05 02:25:45 +02:00
Make timer easier to start for the future
This commit is contained in:
parent
e0e2f02e0b
commit
1f8a8d1ce5
2 changed files with 22 additions and 7 deletions
|
@ -63,18 +63,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
NSLog("Audiobookself is now in the background")
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
|
||||
NSLog("Audiobookself is now in the foreground")
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
NSLog("Audiobookself is now active")
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
NSLog("Audiobookself is terminating")
|
||||
}
|
||||
|
||||
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
||||
|
|
|
@ -52,6 +52,22 @@ class PlayerHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static func startTickTimer() {
|
||||
DispatchQueue.runOnMainQueue {
|
||||
NSLog("Starting the tick timer")
|
||||
timer?.invalidate()
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
|
||||
self.tick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static func stopTickTimer() {
|
||||
NSLog("Stopping the tick timer")
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
}
|
||||
|
||||
public static func startPlayback(session: PlaybackSession, playWhenReady: Bool, playbackRate: Float) {
|
||||
if player != nil {
|
||||
player?.destroy()
|
||||
|
@ -63,11 +79,7 @@ class PlayerHandler {
|
|||
self.session = session
|
||||
player = AudioPlayer(playbackSession: session, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
||||
|
||||
DispatchQueue.runOnMainQueue {
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
|
||||
self.tick()
|
||||
}
|
||||
}
|
||||
startTickTimer()
|
||||
}
|
||||
|
||||
public static func stopPlayback() {
|
||||
|
@ -75,8 +87,7 @@ class PlayerHandler {
|
|||
player?.pause()
|
||||
|
||||
// Stop updating progress before we destory the player, so we don't receive bad data
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
stopTickTimer()
|
||||
|
||||
player?.destroy()
|
||||
player = nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue