Tag: avaudioplayer

如何用AVAudioPlayer从时间t1到t2在Xcode中播放mp3文件

我不知道是否有一个更优雅的方式播放AVAudioPlayer类的MP3文件,从t1到t2时间,而不使用NSTimers?

在应用程序中创build一个UISlider进度条和计时器(如iPod播放器)

我search了Google和StackOverflow两天,还没有find一个清晰,简洁的答案。 我的目标是创build一个滑块/进度条,允许用户擦洗歌曲的不同部分,两边都有两个标签,一个显示已用时间,另一个显示歌曲剩余时间。 我正在使用DiracAudioPlayer,它也包含AVAudioPlayerfunction。 任何帮助或方向的教程是不胜感激。

添加声音从NSDatePicker播放时间

我正在创build一个项目,要求用户能够设置一个声音在特定的时间播放,我目前正在做与本地通知。 我想改变使用AVAudioPlayer ,我想知道,什么是最好的方法? 我目前得到的对象是一个NSDatePicker和一个stringFromDatestring。 我的目标是创build一个闹钟,以便用户可以使用NSDatePicker设置一个时间,那时声音就会消失。

Swift 3 iOS – 与AVAudioPlayer同步暂停

我正在使用AVAudioPlayer在播放器风格的界面(播放/暂停/停止)中播放一组同步的MP3文件。 我知道我可以通过使用play(atTime :)同步玩他们,但我的问题是,我如何同步暂停他们? 目前,暂停他们,我正在使用: for (_, audioTrackPlayer) in audioTrackPlayers.enumerated() { audioTrackPlayer.pause() } 但当然,他们都是一个接一个的停下来。 没有等效的暂停(atTime :)function。 那么如何实现精确的同步暂停呢? 编辑 – 额外信息 在马特询问有多明显之后,我得到了一些数据。 暂停5个曲目需要几乎半秒的时间。 为了说明这一点,我在暂停循环之后添加了一个单独的循环,以在每个轨道上报告currentTime,并在暂停之前添加了几个循环 – 供参考,并显示它们同步开始。 Loop benchmark, 0: 3.2118820861678 Loop benchmark, 0: 3.21580498866213 Loop benchmark, 0: 3.21888888888889 Loop benchmark, 0: 3.22126984126984 Loop benchmark, 0: 3.22328798185941 Before pause, 0: 3.22560090702948 Before pause, 1: 3.22750566893424 Before pause, 2: […]

带有AVAudioPlayer的SKEmiterNode用于音乐视觉效果

请有人帮助! 我希望使用AVAudioPlayer将我的SKEmiterNode的音阶(意义上的大小)变得越来越小。 现在这几乎是我所有的SKEmiterNode,它看起来很棒: beatParticle?.position = CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.5) var beatParticleEffectNode = SKEffectNode() beatParticleEffectNode.addChild(beatParticle!) self.addChild(beatParticleEffectNode) 所有的外观都在.sks文件中完成。 这里是我在一个连续循环中称之为“updateBeatParticle”函数的地方,这样它就可以把我的代码放在音乐上,使得粒子的尺度(意思是尺寸)越来越小。 var dpLink : CADisplayLink? dpLink = CADisplayLink(target: self, selector: "updateBeatParticle") dpLink?.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes) func updateBeatParticle(){ //Put code here } 任何想法我可以做到这一点? 我看了一些这样的教程: https : //www.raywenderlich.com/36475/how-to-make-a-music-visualizer-in-ios 但是,我不能很好的理解它,因为他们使用的是一个emitterLayer,它在Obj-C中,并且对于其他的精彩人物也有兴趣。

在拨打iOS sdk的电话中播放音乐文件的问题

我有两个代码段: 代码1 – 这是通过入耳式扬声器播放音乐文件: NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"8Ocean.mp3"]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:tileDirectory]; NSError *error=nil; self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error]; if(!error) { [self.audioPlayer prepareToPlay]; UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord; AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory); [self.audioPlayer play]; } else { NSLog(@"%@",error.localizedDescription); } 代码2-在通话过程中播放音乐文件(根据用户在通话过程中的设置发送到入耳式或免提式电话) NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"8Ocean.mp3"]; NSURL *fileURL = [[NSURL […]

Swift – 有一个audio重复,但它会间隔?

在Swift中 ,我播放了一首歌,它在viewDidLoad中播放。 它长16秒,全部播放16秒。 我希望它永远重复。 我做了一个NSTimer ,每16秒播放一首歌。 但是,当应用程序加载时,它播放16秒,停止16秒,播放等。 println("just doing some dandy debugging here.") 行 println("just doing some dandy debugging here.") 每16秒打印一次。 这是如何修复的? 码: //these var's are created on the top of the file. var soundTimer: NSTimer = NSTimer() var audioPlayer2 = AVAudioPlayer() var soundTwo = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("sound", ofType: "wav")) //this stuff is in the viewDidLoad […]

AVAudioPlayer在后台没有响应

当我的应用程序收到voip通知时,我在后台播放audio。 但AVAudioPlayerperformance怪异,有时会播放audio,有时并非没有任何错误。 多数民众赞成我是如何玩: func playAudio() { // Set the sound file name & extension let alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("testAudio", ofType: "wav")!) // Play the sound do { try audioPlayer = AVAudioPlayer(contentsOfURL: alertSound) audioPlayer.delegate = self if (audioPlayer.prepareToPlay()) { audioPlayer.play() } else {NSLog("there is error")} } catch { NSLog("there is \(error)") } } 我在我的AppDelegate应用程序函数中初始化AVAudioSession: do { […]

使用AVAudioPlayer播放多个audio文件

我在主StoryBoard上创build了3个UIButtons。 当我按下“button1”或“button2”时,每个播放audio文件(“播放器1”,“播放器2”)。当audio播放时,UIButton被设置为selected 。 我想“Button3”在一行中实现多个函数。 这意味着当我按下“button3”时,应该首先播放“播放器3”,然后在“播放器1”之后播放“播放器2”。 然而,当我按下“Button3”时,同时播放“播放器1”和“播放器2”,因为前一个结束没有延迟。 我发现设置AVAudioPlayer的代理或使用AVQueuePlayer将解决这个问题,但是我发现很难做出改变。 fileprivate var player1:AVAudioPlayer? fileprivate var player2:AVAudioPlayer? fileprivate var player3:AVAudioPlayer? @IBAction func pushButton1(sender: UIButton) { audioPlayer1(url: url1) } @IBAction func pushButton2(sender: UIButton) { audioPlayer2(url: url2) } @IBAction func pushButton3(_ sender: UIButton) { audioPlayer3(url: url1, url2: url2, url3: url3) } func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) { if (player […]

如何使用Swift采样器播放音调,然后在播放下一个之前暂停?

我有代码来获取string中的字母序列,并将其解释为笔记。 代码然后将播放音符。 问题是他们都在同一时间玩。 我怎么把它们当作四分音符来演奏,主要是为了演奏一个音符,等待它结束,然后演奏下一个音符? @IBAction func playButton(sender: AnyObject) { fractalEngine.output = "adgadefe" var notes = Array(fractalEngine.output.characters) var counter = 0 while counter < notes.count { var note = notes[counter] if note == "a" { play(58) } else if note == "b" { play(59) } else if note == "c" { play(60) } else if note […]