如何修剪或从iTunes库中裁剪音乐

我想从用户库中获取音乐音乐指法的音乐。 我所需要的只是每首歌曲的30秒。 我该怎么办呢? 我不需要保存audio,只是使用它。

iOSaudio修剪

用iOS修剪audio

上述2个环节的路要走吗?

感谢您阅读并赞赏任何评论。

干杯

要访问用户已经在他的设备库中的音乐,您可以使用MPMediaItemCollection类 。 在“添加音乐”示例中的Apple文档中也可以find使用此代码的示例代码(虽然稍微老一点,但不使用ARC)。

我不确定您使用的是哪种audio播放器,但是如果您想要在歌曲或audio文件中查找特定点,则可以使用AVAudioPlayer类中的currentTime属性(在Apple文档中指出) 。

要实现这一点,你可以做一些简单的事情:

 yourAudioPlayer.currentTime = 60; 

这会使歌曲跳到1分钟的标记。 在歌曲播放之前,我不能100%确定如何做到这一点,但在开始播放之前,我会把它放在Play IBAction中:

 - (IBAction) playOrPause: (id) sender { if (self.player.playing) { [self.button setTitle: @"Play" forState: UIControlStateHighlighted]; [self.button setTitle: @"Play" forState: UIControlStateNormal]; [self.player pause]; } else { [self.button setTitle: @"Pause" forState: UIControlStateHighlighted]; [self.button setTitle: @"Pause" forState: UIControlStateNormal]; [self.player.currentTime = 60]; //Set the seeker here [self.player play]; } } 

要在一定的时间(你说30秒)后停止播放,你可以使用一个NSTimer,在延迟30秒之后调用播放器stop播放。 就像是:

  [NSTimer scheduledTimerWithTimeInterval:30.0 target:self.player selector:@selector(stop) userInfo:nil repeats:NO]; 

如果你把它放在你用来玩的IBAction中,那就应该这样做!