Skip to content

Commit

Permalink
修改wantedAudio
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Nov 29, 2023
1 parent 17f87e4 commit f895ff0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
14 changes: 0 additions & 14 deletions Package.resolved

This file was deleted.

13 changes: 7 additions & 6 deletions Sources/KSPlayer/AVPlayer/KSOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,16 @@ open class KSOptions {
}

/// wanted video stream index, or nil for automatic selection
/// - Parameter : video bitRate
/// - Returns: The index of the bitRates
open func wantedVideo(tracks _: [MediaPlayerTrack]) -> Int?{
/// - Parameter : video track
/// - Returns: The index of the track
open func wantedVideo(tracks _: [MediaPlayerTrack]) -> Int? {
nil
}

/// wanted audio stream index, or nil for automatic selection
/// - Parameter : audio bitRate and language
/// - Returns: The index of the infos
open func wantedAudio(infos _: [(bitRate: Int64, language: String?)]) -> Int? {
/// - Parameter : audio track
/// - Returns: The index of the track
open func wantedAudio(tracks _: [MediaPlayerTrack]) -> Int? {
nil
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/KSPlayer/MEPlayer/MEPlayerItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,6 @@ extension MEPlayerItem {
var videoIndex: Int32 = -1
if !options.videoDisable {
let videos = assetTracks.filter { $0.mediaType == .video }
let bitRates = videos.map(\.bitRate).filter {
$0 > 0
}
let wantedStreamNb: Int32
if !videos.isEmpty, let index = options.wantedVideo(tracks: videos) {
wantedStreamNb = videos[index].trackID
Expand Down Expand Up @@ -385,6 +382,9 @@ extension MEPlayerItem {
if first.codecpar.codec_id != AV_CODEC_ID_MJPEG {
videoAudioTracks.append(track)
}
let bitRates = videos.map(\.bitRate).filter {
$0 > 0
}
if bitRates.count > 1, options.videoAdaptable {
let bitRateState = VideoAdaptationState.BitRateState(bitRate: first.bitRate, time: CACurrentMediaTime())
videoAdaptation = VideoAdaptationState(bitRates: bitRates.sorted(by: <), duration: duration, fps: first.nominalFrameRate, bitRateStates: [bitRateState])
Expand All @@ -394,7 +394,7 @@ extension MEPlayerItem {

let audios = assetTracks.filter { $0.mediaType == .audio }
let wantedStreamNb: Int32
if !audios.isEmpty, let index = options.wantedAudio(infos: audios.map { ($0.bitRate, $0.language) }) {
if !audios.isEmpty, let index = options.wantedAudio(tracks: audios) {
wantedStreamNb = audios[index].trackID
} else {
wantedStreamNb = -1
Expand Down

0 comments on commit f895ff0

Please sign in to comment.