2022-04-11 16:29:19 +02:00
|
|
|
//
|
|
|
|
// PlayerHandler.swift
|
|
|
|
// App
|
|
|
|
//
|
|
|
|
// Created by Rasmus Krämer on 11.04.22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
class PlayerHandler {
|
|
|
|
private static var player: AudioPlayer?
|
2022-04-12 14:28:47 +02:00
|
|
|
private static var session: PlaybackSession?
|
2022-04-11 16:29:19 +02:00
|
|
|
|
2022-04-14 11:54:53 +02:00
|
|
|
public static func startPlayback(session: PlaybackSession, playWhenReady: Bool) {
|
2022-04-12 14:28:47 +02:00
|
|
|
if player != nil {
|
|
|
|
player?.destroy()
|
|
|
|
player = nil
|
|
|
|
}
|
2022-04-14 11:54:53 +02:00
|
|
|
|
2022-04-14 12:24:27 +02:00
|
|
|
NowPlayingInfo.setSessionMetadata(metadata: NowPlayingMetadata(id: session.id, itemId: session.libraryItemId!, artworkUrl: session.coverPath, title: session.displayTitle ?? "Unknown title", author: session.displayAuthor, series: nil))
|
2022-04-14 11:54:53 +02:00
|
|
|
self.session = session
|
|
|
|
player = AudioPlayer(playbackSession: session, playWhenReady: playWhenReady)
|
2022-04-11 16:29:19 +02:00
|
|
|
}
|
|
|
|
}
|