From d3f89fb797fc90c95927c8f0244358ac3ed912f8 Mon Sep 17 00:00:00 2001 From: kingslay Date: Wed, 13 Dec 2023 20:32:37 +0800 Subject: [PATCH] fix #690 --- Sources/KSPlayer/AVPlayer/KSAVPlayer.swift | 10 +++------- Sources/KSPlayer/AVPlayer/MediaPlayerProtocol.swift | 8 +++++++- Sources/KSPlayer/MEPlayer/FFmpegAssetTrack.swift | 6 +++--- Sources/KSPlayer/Video/IOSVideoPlayerView.swift | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Sources/KSPlayer/AVPlayer/KSAVPlayer.swift b/Sources/KSPlayer/AVPlayer/KSAVPlayer.swift index 1b67936e9..5c939474d 100644 --- a/Sources/KSPlayer/AVPlayer/KSAVPlayer.swift +++ b/Sources/KSPlayer/AVPlayer/KSAVPlayer.swift @@ -516,7 +516,7 @@ class AVMediaPlayerTrack: MediaPlayerTrack { let rotation: Int16 = 0 let bitRate: Int64 let name: String - let language: String? + let languageCode: String? let mediaType: AVFoundation.AVMediaType let isImageSubtitle = false var dovi: DOVIDecoderConfigurationRecord? @@ -535,17 +535,13 @@ class AVMediaPlayerTrack: MediaPlayerTrack { self.track = track trackID = track.assetTrack?.trackID ?? 0 mediaType = track.assetTrack?.mediaType ?? .video - #if os(xrOS) name = track.assetTrack?.languageCode ?? "" - language = track.assetTrack?.extendedLanguageTag + languageCode = track.assetTrack?.languageCode nominalFrameRate = track.assetTrack?.nominalFrameRate ?? 24.0 bitRate = Int64(track.assetTrack?.estimatedDataRate ?? 0) + #if os(xrOS) isPlayable = false #else - name = track.assetTrack?.languageCode ?? "" - language = track.assetTrack?.extendedLanguageTag - nominalFrameRate = track.assetTrack?.nominalFrameRate ?? 24.0 - bitRate = Int64(track.assetTrack?.estimatedDataRate ?? 0) isPlayable = track.assetTrack?.isPlayable ?? false #endif // swiftlint:disable force_cast diff --git a/Sources/KSPlayer/AVPlayer/MediaPlayerProtocol.swift b/Sources/KSPlayer/AVPlayer/MediaPlayerProtocol.swift index ae11427b4..2095c763d 100644 --- a/Sources/KSPlayer/AVPlayer/MediaPlayerProtocol.swift +++ b/Sources/KSPlayer/AVPlayer/MediaPlayerProtocol.swift @@ -109,7 +109,7 @@ public protocol MediaPlayerDelegate: AnyObject { public protocol MediaPlayerTrack: AnyObject, CustomStringConvertible { var trackID: Int32 { get } var name: String { get } - var language: String? { get } + var languageCode: String? { get } var mediaType: AVFoundation.AVMediaType { get } var nominalFrameRate: Float { get } var bitRate: Int64 { get } @@ -180,6 +180,12 @@ extension FFmpegFieldOrder: CustomStringConvertible { // swiftlint:enable identifier_name public extension MediaPlayerTrack { + var language: String? { + languageCode.flatMap { + Locale.current.localizedString(forLanguageCode: $0) + } + } + var codecType: FourCharCode { mediaSubType.rawValue } diff --git a/Sources/KSPlayer/MEPlayer/FFmpegAssetTrack.swift b/Sources/KSPlayer/MEPlayer/FFmpegAssetTrack.swift index 63d7094ec..73e37ac3e 100644 --- a/Sources/KSPlayer/MEPlayer/FFmpegAssetTrack.swift +++ b/Sources/KSPlayer/MEPlayer/FFmpegAssetTrack.swift @@ -12,7 +12,7 @@ public class FFmpegAssetTrack: MediaPlayerTrack { public private(set) var trackID: Int32 = 0 public let codecName: String public var name: String = "" - public private(set) var language: String? + public private(set) var languageCode: String? public private(set) var nominalFrameRate: Float = 0 public private(set) var bitRate: Int64 = 0 public let mediaType: AVFoundation.AVMediaType @@ -97,9 +97,9 @@ public class FFmpegAssetTrack: MediaPlayerTrack { } if let value = metadata["language"], value != "und" { - language = Locale.current.localizedString(forLanguageCode: value) + languageCode = value } else { - language = nil + languageCode = nil } if let value = metadata["title"] { name = value diff --git a/Sources/KSPlayer/Video/IOSVideoPlayerView.swift b/Sources/KSPlayer/Video/IOSVideoPlayerView.swift index 89a14b14b..b253a8bc0 100644 --- a/Sources/KSPlayer/Video/IOSVideoPlayerView.swift +++ b/Sources/KSPlayer/Video/IOSVideoPlayerView.swift @@ -33,7 +33,7 @@ open class IOSVideoPlayerView: VideoPlayerView { fullScreenDelegate?.player(isMaskShow: isMaskShow, isFullScreen: landscapeButton.isSelected) } } - + #if !os(xrOS) private var brightness: CGFloat = UIScreen.main.brightness { didSet {