Skip to content

Commit

Permalink
Added a new function 'currentMediaTrack' to get the current track fro…
Browse files Browse the repository at this point in the history
…m the VersaPlayerItem
  • Loading branch information
selvinn committed Mar 29, 2021
1 parent 0f0174a commit 5bdf9fb
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions VersaPlayer/Classes/Source/Core/Player/VersaPlayerItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,31 @@ open class VersaPlayerItem: AVPlayerItem {
deinit {

}

private func convert(with mediaSelectionOption: AVMediaSelectionOption, group: AVMediaSelectionGroup) -> VersaPlayerMediaTrack {
let title = mediaSelectionOption.displayName
let language = mediaSelectionOption.extendedLanguageTag ?? "none"
return VersaPlayerMediaTrack(option: mediaSelectionOption, group: group, name: title, language: language)
}

private func tracks(for characteristic: AVMediaCharacteristic) -> [VersaPlayerMediaTrack] {
guard let group = asset.mediaSelectionGroup(forMediaCharacteristic: characteristic) else {
return []
}
let options = group.options
let tracks = options.map { (option) -> VersaPlayerMediaTrack in
let title = option.displayName
let language = option.extendedLanguageTag ?? "none"
return VersaPlayerMediaTrack(option: option, group: group, name: title, language: language)
return convert(with: option, group: group)
}
return tracks
}

public func currentMediaTrack(for characteristic: AVMediaCharacteristic) -> VersaPlayerMediaTrack? {

if let tracks = asset.mediaSelectionGroup(forMediaCharacteristic: characteristic), let currentTrack = currentMediaSelection.selectedMediaOption(in: tracks) {
return convert(with: currentTrack, group: tracks)
}

return nil
}

}

0 comments on commit 5bdf9fb

Please sign in to comment.