avaudioplayer

Detecting end of the playback in AVAudioPlayer

天大地大妈咪最大 提交于 2019-12-11 05:32:21
问题 I've got couple of short .mp3 sounds which I'm storing in the array and would like to play them consecutively. Is there any way to detect when AVAudioPlayer stopped playing so that I could call a completion handler and play next sound? I know that there is a delegate for that but I'm using Playground and SKScene. 回答1: Hellp @codddeer123, AVAudioPlayer contains AVAudioPlayerDelegte method which is called on audio playing completed. I have implemented it as extension of my class, you can do as

URL is nil in AVAudioFile

心已入冬 提交于 2019-12-11 05:28:54
问题 I am trying to play multiple audio files on top of a background audio file using AVAudioEngine. When I try to initialize backgroundAudioFile , the app crashes saying :Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.coreaudio.avfaudio Code=2003334207 "(null)" UserInfo={failed call=ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)}. The url passed to the initializer is valid. It is printed out. import Foundation import AVFoundation class

Playing Multiple Sounds at Once Using AVAudioPlayer

旧街凉风 提交于 2019-12-11 05:15:03
问题 I have a set of UIButtons. Every time I press a button, a sound plays. The issue: When you press one button and the sound behind to play, when you press the second button the sound coming from the first button stops. This question has been asked a million times. The solution is always to create a new instance of AVAudioPlayer each time. I've tried that, to no avail. I've read the docs, read through every question on StackOverflow related to this, and have had no luck. When I use SystemSoundID

avaudioplayer playingsong

拜拜、爱过 提交于 2019-12-11 04:50:07
问题 I created instance AVAudioPlayer but the instance is working only once like if I give if(a.playing) { i=1 } else { i=2 } for 1st time its giving i=1 while playing and other times its giving i=2 while playing. 回答1: AVAudioPlayer reference Reference clearly mentions this about the playing property Important: Do not poll this property (that is, do not use it inside of a loop) in an attempt to discover when playback has stopped. Perhaps u can try [audioPlayer isPlaying]; 来源: https://stackoverflow

Simple Rewind for AVAudioplayer

三世轮回 提交于 2019-12-11 04:39:17
问题 I've got valuechanged event handler like that: -(void)scrub:(id)sender { if(self.audioPlayer.playing) { self.audioPlayer.pause; self.audioPlayer.currentTime=self.scrubber.value; self.audioPlayer.play; } } Why doesn't rewind happen? what should I add? thanks! Moreover, how to display current time in a label? 回答1: To set the time, you can do: [audioPlayer setTime:self.scrubber.value]; However, you need to verify that that is actually a number. You also need to make sure it has an appropriate

System sound becomes louder when AVAudioPlayer is initiated

那年仲夏 提交于 2019-12-11 04:27:00
问题 I've found 1 question on SO about the same issue and it remains unanswered. AVAudioPlayer affects system sounds AVAudioSessionCategoryAmbient is not the answer as that only allows the app to play its audio simultaneously with another app's audio, that's not it. I play sound effects such as button clicking sounds etc with SystemSound and background music with AVAudioPlayer. When AVAudioPlayer starts while SystemSound is being played, that particular system sound becomes like 5 times louder all

Trigger AVAudioPlayer to stop all sounds and play selected except when playing(selected) button is clicked

自闭症网瘾萝莉.ら 提交于 2019-12-11 03:56:32
问题 I am creating a sound board app that plays one sound at a time. I would like a UIButton to be able to stop all other sounds playing and start playing its own sound when clicked. I have a single AVAudioPlayer set up to play all sounds (I change the sound file url when clicked and since I only want one sound at a time playing this is not an issue). I would like to know how to stop all other sounds and play the sound according to the button pressed, but if the button clicked is the button with

Reconciling CACurrentMediaTime() and deviceCurrentTime

人盡茶涼 提交于 2019-12-11 03:23:57
问题 I am trying to synchronize several CABasicAnimations with AVAudioPlayer . The issue I have is that CABasicAnimation uses CACurrentMediaTime() as a reference point when scheduling animations while AVAudioPlayer uses deviceCurrentTime . Also for the animations, CFTimeInterval is used, while for sound it's NSTimeInterval (not sure if they're "toll free bridged" like other CF and NS types). I'm finding that the reference points are different as well. Is there a way to ensure that the sounds and

Audio player duration changes while playing

不问归期 提交于 2019-12-11 03:22:07
问题 When I take the duration of an audio file before playing it with: audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; ... [audioPlayer prepareToPlay]; duration = audioPlayer.duration; I get a duration of for example 16.71s. Then when taking samples every 0.2s while playing, the duration changes. It changes every 1.2 to 1.6 seconds to: 16.71s, 17.02s, 17.23s, 17.33s, 17.38s, 17.43s, 17.38s, 17.29s, 17.31s, then stays at 17.51s for the last 2.5 seconds. So it goes up

Use MPMediaPicker selections as AVAudioPlayer inputs

旧时模样 提交于 2019-12-11 02:48:46
问题 I'm programming an application for the hearing-impaired. I'm hoping to take tracks from the iTunes library, and in my app have a slider for panning. I don't want to use OpenAL (this isn't a game - I repeat this is a media player). So since AVAudioPlayer has the easy pan method, can I take selections from the MPMediaPicker and feed them into the AVAudioPlayer so I can pan them? 回答1: I dont do a lot of iOS development, but I believe there are two ways. Method #1 You need to add /System/Library