-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathAudioQueueLibrary.swift
44 lines (36 loc) · 1023 Bytes
/
AudioQueueLibrary.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// AudioQueueLibrary.swift
// ModernAVPlayer_Example
//
// Created by ankierman on 23/05/2020.
// Copyright © 2020 CocoaPods. All rights reserved.
//
import Foundation
import ModernAVPlayer
protocol AudioQueueLibrary: class {
var dataSource: [ModernAVPlayerMedia] { get }
var index: Int { get }
var selectedMedia: ModernAVPlayerMedia { get }
func changeMedia(userAction: ModernAudioQueueLibrary.UserAction)
}
final class ModernAudioQueueLibrary: AudioQueueLibrary {
enum UserAction {
case prevTrack, nextTrack
}
private var selectedMediaIndex = 0
let dataSource = AudioQueueResource.localMedias()
var index: Int {
abs(selectedMediaIndex % dataSource.count)
}
var selectedMedia: ModernAVPlayerMedia {
dataSource[index]
}
func changeMedia(userAction: UserAction) {
switch userAction {
case .prevTrack:
selectedMediaIndex -= 1
case .nextTrack:
selectedMediaIndex += 1
}
}
}