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 preferredTrackIndex: Int = 0
|
||||
|
||||
// MARK: - 初始化
|
||||
|
||||
func setup() {
|
||||
@ -340,14 +343,17 @@ final class PlayerBridge: ObservableObject {
|
||||
|
||||
let options = group.options
|
||||
availableTracks = options.enumerated().map { idx, _ in "Track \(idx + 1)" }
|
||||
currentTrackIndex = 0
|
||||
|
||||
// 选择默认音轨
|
||||
if let defaultOpt = group.defaultOption,
|
||||
let idx = options.firstIndex(of: defaultOpt) {
|
||||
currentTrackIndex = idx
|
||||
// 使用用户偏好音轨(如果存在),否则用默认
|
||||
var targetIndex = preferredTrackIndex
|
||||
if targetIndex >= options.count {
|
||||
targetIndex = 0
|
||||
}
|
||||
|
||||
// 应用选中的音轨
|
||||
item.select(options[targetIndex], in: group)
|
||||
currentTrackIndex = targetIndex
|
||||
|
||||
updateTrackLabel()
|
||||
}
|
||||
}
|
||||
@ -361,6 +367,7 @@ final class PlayerBridge: ObservableObject {
|
||||
|
||||
item.select(group.options[index], in: group)
|
||||
currentTrackIndex = index
|
||||
preferredTrackIndex = index // 记住用户偏好
|
||||
updateTrackLabel()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user