适用于iOS应用的多轨mp3播放

编程入门 行业动态 更新时间:2024-10-26 06:37:19
本文介绍了适用于iOS应用的多轨mp3播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在做一个涉及播放多轨格式的歌曲(鼓,人声,吉他,钢琴等)的应用程序。我不需要对每个音轨进行任何精美的音频处理,我所需要做的就是播放,暂停和静音/取消静音每个音轨。

I am doing an application that involves playing back a song in a multi track format (drums, vocals, guitar, piano, etc...). I don't need to do any fancy audio processing to each track, all I need to be able to do is play, pause, and mute/unmute each track.

我一直在使用AVAudioPlayer的多个实例,但是在进行设备测试时,我注意到曲目在首次播放时的播放非常不同步。此外,当我暂停播放曲目时,它们会继续变得不同步。经过一番研究,我发现AVAudioplayer的延迟太长,无法在我的应用程序中使用。

I had been using multiple instances of AVAudioPlayer but when performing device testing, I noticed that the tracks are playing very slightly out of sync when they are first played. Furthermore, when I pause and play the tracks they continue to get more out of sync. After a bit of research I've realized that AVAudioplayer just has too much latency and won't work for my application.

在我的应用程序中,我基本上有一个NSArray of AVAudioPlayers我会循环播放并播放每个或暂停/停止每个播放,我确定这是导致它在设备上不同步的原因。

In my application I basically had an NSArray of AVAudioPlayers that I would loop through and play each one or pause/stop each one, I'm sure this is what caused it to get out of sync on the device.

它似乎苹果的音频混音器对我来说效果很好,但是当我尝试实现它时,我遇到一个EXC_BAD_ACCESS错误,我无法弄清。

It seemed like apple's audio mixer would work well for me, but when I try implementing it I get a EXC_BAD_ACCESS error that I can't figure out.

我知道答案是使用OpenAL或音频单元,但是当我需要同时播放5个.mp3音轨时,似乎不需要花几个星期来学习这些内容。有人对如何做到这一点有什么建议吗?谢谢

I know the answer is to use OpenAL or audio units but It just seems unnecessary to spend weeks learning about these when all I need to do is play around 5 .mp3 tracks at the same time. Does anyone have any suggestions on how to accomplish this? Thanks

推荐答案

感谢admsyn的建议,我能够提出解决方案。

thanks to admsyn's suggestion I was able to come up with a solution.

AVAudioPlayer具有currentTime属性,该属性返回轨道的当前时间,也可以对其进行设置。

AVAudioPlayer has a currentTime property that returns the current time of a track and can also be set.

因此,我实现了admsyn所述的startSynchronizedPlayback,然后当我停止跟踪时添加了以下内容:

So I implemented the startSynchronizedPlayback as stated by admsyn and then added the following when I stopped the tracks:

-(void) stopAll { int count = [tracksArr count]; for(int i = 0; i < count; i++) { trackModel = [tracksArr objectAtIndex:i] if(i = 0) { currentTime = [trackModel currentTime] } [trackModel stop] [trackModel setCurrentTime:currentTime] } {

这段代码基本上遍历了我的音轨数组,每个音轨都拥有自己的AVAudioPlayer,从第一个音轨中获取当前时间,然后设置所有当时的以下曲目。现在,当我使用startSynchronizedPlayback方法时,它们都将同步播放,暂停暂停将使它们也保持同步。希望这对其他尝试保持同步的人有所帮助。

This code basically loops through my array of tracks which each hold their own AVAudioPlayer, grabs the current time from the first track, then sets all of the following tracks to that time. Now when I use the startSynchronizedPlayback method they all play in sync, and pausing unpausing keeps them in sync as well. Hope this is helpful to someone else trying to keep tracks in sync.

更多推荐

适用于iOS应用的多轨mp3播放

本文发布于:2023-11-23 15:39:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621987.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!