fix: persist audio track selection across songs (preferredTrackIndex)
This commit is contained in:
parent
bf4cb64286
commit
4e58377582
@ -70,6 +70,9 @@ final class PlayerBridge: ObservableObject {
|
|||||||
// 缓存时长
|
// 缓存时长
|
||||||
private var cachedDuration: Double = 0
|
private var cachedDuration: Double = 0
|
||||||
|
|
||||||
|
// 用户偏好音轨(跨歌曲保持)
|
||||||
|
private var preferredTrackIndex: Int = 0
|
||||||
|
|
||||||
// MARK: - 初始化
|
// MARK: - 初始化
|
||||||
|
|
||||||
func setup() {
|
func setup() {
|
||||||
@ -340,14 +343,17 @@ final class PlayerBridge: ObservableObject {
|
|||||||
|
|
||||||
let options = group.options
|
let options = group.options
|
||||||
availableTracks = options.enumerated().map { idx, _ in "Track \(idx + 1)" }
|
availableTracks = options.enumerated().map { idx, _ in "Track \(idx + 1)" }
|
||||||
currentTrackIndex = 0
|
|
||||||
|
|
||||||
// 选择默认音轨
|
// 使用用户偏好音轨(如果存在),否则用默认
|
||||||
if let defaultOpt = group.defaultOption,
|
var targetIndex = preferredTrackIndex
|
||||||
let idx = options.firstIndex(of: defaultOpt) {
|
if targetIndex >= options.count {
|
||||||
currentTrackIndex = idx
|
targetIndex = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 应用选中的音轨
|
||||||
|
item.select(options[targetIndex], in: group)
|
||||||
|
currentTrackIndex = targetIndex
|
||||||
|
|
||||||
updateTrackLabel()
|
updateTrackLabel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,6 +367,7 @@ final class PlayerBridge: ObservableObject {
|
|||||||
|
|
||||||
item.select(group.options[index], in: group)
|
item.select(group.options[index], in: group)
|
||||||
currentTrackIndex = index
|
currentTrackIndex = index
|
||||||
|
preferredTrackIndex = index // 记住用户偏好
|
||||||
updateTrackLabel()
|
updateTrackLabel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user