gpt4 book ai didi

ios - StreamingKit 重复歌曲 ios

转载 作者:行者123 更新时间:2023-11-30 12:24:41 27 4
gpt4 key购买 nike

我在播放本地(保存在设备上)歌曲队列时遇到问题。我正在使用这个 cocoapod - https://github.com/tumtumtum/StreamingKit 。我队列中的第一个项目在完成后开始再次播放。它的 stopReason 状态为 NONE

    func audioPlayer(_ audioPlayer: STKAudioPlayer, didFinishPlayingQueueItemId queueItemId: NSObject, with stopReason: STKAudioPlayerStopReason, andProgress progress: Double, andDuration duration: Double) {

if stopReason == .eof || stopReason == .pendingNext {
checkNextTrack()
}

if stopReason == .none {
print("NONE")
}

if stopReason == .error || stopReason == .userAction || stopReason == .disposed {
stop()
resetAudioPlayer()
}
}

其他元素的状态为 .eof.pendingNext,这是正确的行为。这种情况我该怎么办?所有远程 URL 均可正常播放。谢谢!

更新:队列创建

    internal func playWithQueue(queue: [Song], index: Int = 0) {
var audioListNew = [AudioItem]()
for (index, value) in queue.enumerated() {
let audioItem = AudioItem(audioItem: value, audioIndex: index)
audioListNew.append(audioItem)
}

guard index >= 0 && index < audioListNew.count else { return }
newQueue(queue: audioListNew, index: index)
}


func newQueue(queue: [AudioItem], index: Int = 0) {
self.queue = queue
audioPlayer.clearQueue()

if let currentSong = self.queue[index].audioItem {
play(file: currentSong)

for (songIndex, _) in queue.enumerated() {
audioPlayer.queue( (queue[Int((index + songIndex) % queue.count)].audioItem?.songRealUrl)! )
}

}

currentIndex = index
}

最佳答案

我也遇到同样的问题,已经解决了!你需要这样做:

    -(void) audioPlayer:(STKAudioPlayer*)audioPlayer didFinishBufferingSourceWithQueueItemId:(NSObject*)queueItemId
{
SampleQueueId* queueId = (SampleQueueId*)queueItemId;

NSLog(@"Requeuing: %@", [queueId.url description]);

// [self.audioPlayer queueDataSource:[STKAudioPlayer dataSourceFromURL:queueId.url] withQueueItemId:[[SampleQueueId alloc] initWithUrl:queueId.url andCount:queueId.count+1]];
}

之后您需要编写停止操作:

    -(void) audioPlayer:(STKAudioPlayer*)audioPlayer didFinishPlayingQueueItemId:(NSObject*)queueItemId withReason:(STKAudioPlayerStopReason)stopReason andProgress:(double)progress andDuration:(double)duration
{
SampleQueueId* queueId = (SampleQueueId*)queueItemId;
NSLog(@"Finished: %@", [queueId.url description]);


if(stopReason == STKAudioPlayerStopReasonEof)
{
if(self.isMainAudioPlay)
{
[self.mainAudioPlayer setState:STKAudioPlayerStateStopped];
[self.mainAudioPlayer stop];
self.playMainAudioFrame.image = [UIImage imageNamed:PlayIconMain];
}
else
{
[self.audioPlayer setState:STKAudioPlayerStateStopped];
[self.audioPlayer stop];

if(self.comments.count > 0)
{
UITableView *tableView = self.tabelView;
RCommentsModel *newsStop = (self.comments)[self.indexpathForStop.row];
newsStop.commentPlayIcon = PlayIconMain;
[self.comments replaceObjectAtIndex:self.indexpathForStop.row withObject:newsStop];

[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[self.indexpathForStop] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
}
}
}
else if (stopReason == STKAudioPlayerStopReasonUserAction)
{
if(self.isMainAudioPlay)
{
[self.mainAudioPlayer setState:STKAudioPlayerStateStopped];
[self.mainAudioPlayer stop];
self.playMainAudioFrame.image = [UIImage imageNamed:PlayIconMain];
}
else
{
[self.audioPlayer setState:STKAudioPlayerStateStopped];
[self.audioPlayer stop];

if(self.comments.count > 0)
{
UITableView *tableView = self.tabelView;

RCommentsModel *newsStop = (self.comments)[self.indexpathForStop.row];
newsStop.commentPlayIcon = PlayIconMain;
[self.comments replaceObjectAtIndex:self.indexpathForStop.row withObject:newsStop];

[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[self.indexpathForStop] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
}
}
}
else if (stopReason == STKAudioPlayerStopReasonNone)
{

}
}

希望它有帮助!:)我花了很多时间来修复它 - 并且它有效!

关于ios - StreamingKit 重复歌曲 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44343670/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com