mirror of
https://github.com/dirtydishes/dreamio.git
synced 2026-06-06 13:37:24 +00:00
merge main into subtitle labels
This commit is contained in:
commit
1b14f4970a
6 changed files with 567 additions and 7 deletions
|
|
@ -18,6 +18,7 @@ final class VLCNativePlaybackBackend: NSObject, NativePlaybackBackend {
|
|||
var onFailure: ((Error) -> Void)?
|
||||
var onStateChange: (() -> Void)?
|
||||
var onSubtitleTracksChange: (() -> Void)?
|
||||
var onAudioTracksChange: (() -> Void)?
|
||||
|
||||
#if canImport(MobileVLCKit)
|
||||
private let mediaPlayer = VLCMediaPlayer()
|
||||
|
|
@ -112,6 +113,19 @@ final class VLCNativePlaybackBackend: NSObject, NativePlaybackBackend {
|
|||
#endif
|
||||
}
|
||||
|
||||
func selectAudioTrack(id: Int32) {
|
||||
#if canImport(MobileVLCKit)
|
||||
#if DEBUG
|
||||
logAudioTracks(reason: "before-select-\(id)")
|
||||
#endif
|
||||
mediaPlayer.currentAudioTrackIndex = id
|
||||
#if DEBUG
|
||||
logAudioTracks(reason: "after-select-\(id)")
|
||||
#endif
|
||||
onAudioTracksChange?()
|
||||
#endif
|
||||
}
|
||||
|
||||
func selectSubtitleTrack(id: Int32) {
|
||||
#if canImport(MobileVLCKit)
|
||||
didUserSelectSubtitleTrack = true
|
||||
|
|
@ -201,6 +215,26 @@ final class VLCNativePlaybackBackend: NSObject, NativePlaybackBackend {
|
|||
#endif
|
||||
}
|
||||
|
||||
var audioTracks: [AudioTrack] {
|
||||
#if canImport(MobileVLCKit)
|
||||
let names = mediaPlayer.audioTrackNames as? [String] ?? []
|
||||
let indexes = mediaPlayer.audioTrackIndexes as? [NSNumber] ?? []
|
||||
return zip(indexes, names).map { index, name in
|
||||
AudioTrack(id: index.int32Value, name: name)
|
||||
}
|
||||
#else
|
||||
[]
|
||||
#endif
|
||||
}
|
||||
|
||||
var selectedAudioTrackID: Int32 {
|
||||
#if canImport(MobileVLCKit)
|
||||
mediaPlayer.currentAudioTrackIndex
|
||||
#else
|
||||
-1
|
||||
#endif
|
||||
}
|
||||
|
||||
var subtitleTracks: [SubtitleTrack] {
|
||||
#if canImport(MobileVLCKit)
|
||||
reconcileExternalSubtitleDisplayNames()
|
||||
|
|
@ -305,6 +339,12 @@ final class VLCNativePlaybackBackend: NSObject, NativePlaybackBackend {
|
|||
}
|
||||
|
||||
#if DEBUG
|
||||
private func logAudioTracks(reason: String) {
|
||||
let names = mediaPlayer.audioTrackNames as? [String] ?? []
|
||||
let indexes = mediaPlayer.audioTrackIndexes as? [NSNumber] ?? []
|
||||
print("[DreamioVLC] audio tracks reason=\(reason) names=\(names) indexes=\(indexes.map { $0.int32Value }) selected=\(mediaPlayer.currentAudioTrackIndex)")
|
||||
}
|
||||
|
||||
private func logSubtitleTracks(reason: String) {
|
||||
let names = mediaPlayer.videoSubTitlesNames as? [String] ?? []
|
||||
let indexes = mediaPlayer.videoSubTitlesIndexes as? [NSNumber] ?? []
|
||||
|
|
@ -396,6 +436,7 @@ extension VLCNativePlaybackBackend: VLCMediaPlayerDelegate {
|
|||
reapplyAutoSelectedSubtitleTrackIfNeeded(reason: stateName(mediaPlayer.state))
|
||||
onReady?()
|
||||
onStateChange?()
|
||||
onAudioTracksChange?()
|
||||
case .error:
|
||||
onFailure?(NativePlaybackError.playbackFailed)
|
||||
case .paused, .stopped, .ended:
|
||||
|
|
@ -403,8 +444,10 @@ extension VLCNativePlaybackBackend: VLCMediaPlayerDelegate {
|
|||
case .esAdded:
|
||||
selectPreferredSubtitleTrackIfNeeded(reason: "esAdded")
|
||||
#if DEBUG
|
||||
logAudioTracks(reason: "esAdded")
|
||||
logSubtitleTracks(reason: "esAdded")
|
||||
#endif
|
||||
onAudioTracksChange?()
|
||||
onSubtitleTracksChange?()
|
||||
default:
|
||||
break
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue