Files
sodalive-ios/SodaLive/Sources/Content/Player/AudioContentPlaylistManager.swift
Yu Sung ee22a0a77e 콘텐츠 플레이어 - 재생목록
- 아이템을 터치했을 때 현재 index도 같이 변경되도록 수정해서 이전/이후 재생시 현재 아이템 기준으로 이전/이후 콘텐츠가 재생되도록 수정
2025-02-26 17:20:12 +09:00

50 lines
1.2 KiB
Swift

//
// AudioContentPlaylistManager.swift
// SodaLive
//
// Created by klaus on 12/16/24.
//
import Foundation
class AudioContentPlaylistManager {
private var currentIndex = -1
let playlist: [AudioContentPlaylistContent]
init(playlist: [AudioContentPlaylistContent]) {
self.playlist = playlist
}
func moveToNext() -> AudioContentPlaylistContent? {
if !playlist.isEmpty {
currentIndex = currentIndex + 1 >= playlist.count ? 0 : currentIndex + 1
return playlist[currentIndex]
}
return nil
}
func moveToPrevious() -> AudioContentPlaylistContent? {
if !playlist.isEmpty {
currentIndex = currentIndex - 1 < 0 ? playlist.count - 1 : currentIndex - 1
return playlist[currentIndex]
}
return nil
}
func findByContentId(contentId: Int) -> AudioContentPlaylistContent? {
if let index = playlist.firstIndex(where: { $0.id == contentId }), !playlist.isEmpty {
currentIndex = index
return playlist[index]
}
return nil
}
func hasNextContent() -> Bool {
return currentIndex + 1 < playlist.count
}
}