Skip to content

Commit

Permalink
Merge pull request #85 from selvinn/get_current_media_track
Browse files Browse the repository at this point in the history
Function to get the current media track
  • Loading branch information
josejuanqm authored Mar 29, 2021
2 parents 0f0174a + 5bdf9fb commit cea94e8
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 cea94e8

Please sign in to comment.