Skip to content

Commit

Permalink
Hide disable track for audio
Browse files Browse the repository at this point in the history
  • Loading branch information
kodlian committed Jan 1, 2019
1 parent 9f8b648 commit 37dde78
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Sources/Panel/Selection/VLCMediaPlayer+indexed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ struct IndexedCollection: SelectableCollection {
let indexesKeyPath: KeyPath<VLCMediaPlayer, [Any]?>
let namesKeyPath: KeyPath<VLCMediaPlayer, [Any]?>
let curentIndexKeyPath: ReferenceWritableKeyPath<VLCMediaPlayer, Int32>
var hideDisableTrack: Bool = false

private var offset: Int {
return hideDisableTrack ? 1 : 0
}

var selectedIndex: Int? {
set {
if let selectedIndex = newValue {
player[keyPath: curentIndexKeyPath] = player[keyPath: indexesKeyPath]?[selectedIndex] as? Int32 ?? 0
player[keyPath: curentIndexKeyPath] = player[keyPath: indexesKeyPath]?[selectedIndex + offset] as? Int32 ?? 0
} else {
player[keyPath: curentIndexKeyPath] = -1
}
Expand All @@ -32,16 +37,19 @@ struct IndexedCollection: SelectableCollection {
return nil
}

return index
return index - offset
}
}

var count: Int {
return player[keyPath: indexesKeyPath]?.count ?? 0
guard let count = player[keyPath: indexesKeyPath]?.count else {
return 0
}
return count - offset
}

subscript(position: Int) -> String {
return player[keyPath: namesKeyPath]?[position] as? String ?? "none"
return player[keyPath: namesKeyPath]?[position + offset] as? String ?? "none"
}
}

Expand All @@ -50,13 +58,15 @@ extension VLCMediaPlayer {
return IndexedCollection(player: self,
indexesKeyPath: \VLCMediaPlayer.audioTrackIndexes,
namesKeyPath: \VLCMediaPlayer.audioTrackNames,
curentIndexKeyPath: \VLCMediaPlayer.currentAudioTrackIndex)
curentIndexKeyPath: \VLCMediaPlayer.currentAudioTrackIndex,
hideDisableTrack: true)
}

var videoSubtitles: IndexedCollection {
return IndexedCollection(player: self,
indexesKeyPath: \VLCMediaPlayer.videoSubTitlesIndexes,
namesKeyPath: \VLCMediaPlayer.videoSubTitlesNames,
curentIndexKeyPath: \VLCMediaPlayer.currentVideoSubTitleIndex)
curentIndexKeyPath: \VLCMediaPlayer.currentVideoSubTitleIndex,
hideDisableTrack: false)
}
}

0 comments on commit 37dde78

Please sign in to comment.