我想在Spotify启用的应用程序中从一条曲目交叉淡入到下一条曲目。这两条曲目都是Spotify曲目,并且由于Spotify一次只能有一个数据流,所以我怀疑我需要在第一首曲目的最后几秒缓冲(我想我可以提前读取1.5倍的播放速度),然后开始播放流对于第二首曲目,使用AudioUnit淡入淡出。如何使用cocoalibspotify音频交叉淡入淡出?
我查看示例应用程序: 万岁 - https://github.com/iKenndac/Viva SimplePlayer与EQ - https://github.com/iKenndac/SimplePlayer-with-EQ并试图让我的脑海里围绕SPCircularBuffer,但我仍然需要帮助。有人能指点我另一个例子吗?或者帮助子弹点轨道交叉淡入淡出游戏计划?
更新:感谢iKenndac,我在那里95%左右。我会后我到目前为止有:
在SPPlaybackManager.m:initWithPlaybackSession:(SPSession *)aSession {
补充说:
self.audioController2 = [[SPCoreAudioController alloc] init];
self.audioController2.delegate = self;
和
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
...
self.audioController.audioOutputEnabled = self.playbackSession.isPlaying;
// for crossfade, add
self.audioController2.audioOutputEnabled = self.playbackSession.isPlaying;
和添加了基于playTrack的新方法
-(void)crossfadeTrack:(SPTrack *)aTrack callback:(SPErrorableOperationCallback)block {
// switch audiocontroller from current to other
if (self.playbackSession.audioDeliveryDelegate == self.audioController)
{
self.playbackSession.audioDeliveryDelegate = self.audioController2;
self.audioController2.delegate = self;
self.audioController.delegate = nil;
}
else
{
self.playbackSession.audioDeliveryDelegate = self.audioController;
self.audioController.delegate = self;
self.audioController2.delegate = nil;
}
if (aTrack.availability != SP_TRACK_AVAILABILITY_AVAILABLE) {
if (block) block([NSError spotifyErrorWithCode:SP_ERROR_TRACK_NOT_PLAYABLE]);
self.currentTrack = nil;
}
self.currentTrack = aTrack;
self.trackPosition = 0.0;
[self.playbackSession playTrack:self.currentTrack callback:^(NSError *error) {
if (!error)
self.playbackSession.playing = YES;
else
self.currentTrack = nil;
if (block) {
block(error);
}
}];
}
此开始用于淡入淡出
crossfadeTimer = [的NSTimer scheduledTimerWithTimeInterval:0.5 目标:自 选择器:@selector(crossfadeCountdown) USERINFO:无 重复:YES]定时器;
而且为了保持第一播放曲目的数据SPCoreAudioController.m加载之后我改变了目标缓冲区长度:
static NSTimeInterval const kTargetBufferLength = 20;
和SPSession.m:音轨结尾(sp_session *会话){
我除去
// sess.playing = NO;
我请preloadTrackForPlayback:轨道的端部约15秒之前,然后crossfadeTrack:在之前10秒。
然后设置crossfadeCountdownTime = [您想要交叉淡入淡出多少秒] * 2;
我褪色与成交量较crosssfade:
- (void) crossfadeCountdown
{
[UIAppDelegate.playbackSPManager setVolume:(1- (((float)crossfadeCountdownTime/ (thisCrossfadeSeconds*2.0)) *0.2))];
crossfadeCountdownTime -= 0.5;
if (crossfadeCountdownTime == 1.0)
{
NSLog(@"Crossfade countdown done");
crossfadeCountdownTime = 0;
[crossfadeTimer invalidate];
crossfadeTimer = nil;
[UIAppDelegate.playbackSPManager setVolume:1.0];
}
}
我会继续做这个工作,和更新,如果我可以做的更好。再次感谢iKenndac提供的帮助!
我试图在CocoaLibSpotify中实现交叉淡入淡出功能,目前我坚持最后一步,淡入淡出音频控制器的音量。你能否详细说明你是如何做到的? – 2015-01-01 17:09:44