Skip to content
Permalink
Browse files

Replace AVAudioPlayer for AVPlayer

  • Loading branch information
GianniCarlo committed Dec 21, 2019
1 parent 0804cf4 commit 9a84fd07012d85e8b7f060dd8bcd40594e29cee3
@@ -50,9 +50,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// register to audio-interruption notifications
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioInterruptions(_:)), name: AVAudioSession.interruptionNotification, object: nil)

// register to audio-route-change notifications
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioRouteChange(_:)), name: AVAudioSession.routeChangeNotification, object: nil)

// update last played book on watch app
NotificationCenter.default.addObserver(self, selector: #selector(self.sendApplicationContext), name: .bookPlayed, object: nil)

@@ -236,33 +233,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

// Handle audio route changes
@objc func handleAudioRouteChange(_ notification: Notification) {
guard PlayerManager.shared.isPlaying,
let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSession.RouteChangeReason(rawValue: reasonValue) else {
return
}

// Pause playback if route changes due to a disconnect
switch reason {
case .oldDeviceUnavailable:
guard let storedPort = PlayerManager.shared.outputPort,
let currentRoute = AVAudioSession.sharedInstance().currentRoute.outputs.first else { return }

guard storedPort != currentRoute else { return }

guard currentRoute.portType == .builtInSpeaker else { return }

DispatchQueue.main.async {
PlayerManager.shared.pause()
}
default:
break
}
}

// For now, seek forward/backward and next/previous track perform the same function
func setupMPRemoteCommands() {
// Play / Pause
@@ -23,9 +23,7 @@ class ItemListViewController: UIViewController, ItemList, ItemListAlerts, ItemLi
@IBOutlet weak var tableView: UITableView!

private var previousLeftButtons: [UIBarButtonItem]?
lazy var selectButton: UIBarButtonItem = {
return UIBarButtonItem(title: "Select All", style: .plain, target: self, action: #selector(selectButtonPressed))
}()
lazy var selectButton: UIBarButtonItem = UIBarButtonItem(title: "Select All", style: .plain, target: self, action: #selector(selectButtonPressed))

var library: Library!

@@ -143,17 +141,16 @@ class ItemListViewController: UIViewController, ItemList, ItemListAlerts, ItemLi
if editing {
self.previousLeftButtons = navigationItem.leftBarButtonItems
self.navigationItem.leftBarButtonItems = [selectButton]
self.selectButton.isEnabled = tableView.numberOfRows(inSection: Section.data.rawValue) > 0
self.selectButton.isEnabled = self.tableView.numberOfRows(inSection: Section.data.rawValue) > 0
self.updateSelectionStatus()
} else {
self.navigationItem.leftBarButtonItems = previousLeftButtons
self.navigationItem.leftBarButtonItems = self.previousLeftButtons
}

NotificationCenter.default.post(name: notification, object: nil, userInfo: nil)
}

func updateSelectionStatus() {

guard self.tableView.isEditing else { return }

self.selectButton.title = self.tableView.numberOfRows(inSection: Section.data.rawValue) > (self.tableView.indexPathsForSelectedRows?.count ?? 0)

0 comments on commit 9a84fd0

Please sign in to comment.
You can’t perform that action at this time.