FAQ Database Discussion Community


toggle audio play back on/off very quickly

ios,avaudioplayer
I'm working on a simple project with one view. When the user presses the view, a tone should play, and when they lift their finger up it should stop. Basically like Morse code. Edit: For clarification, I'm looking for an effect as instant and short as the sound effects the...

How do I get music to persist as I navigate from view to view?

ios,iphone,swift,avaudioplayer,music-player
So, I have mastered the art of playing sounds/music using one view in iOS, but I am now trying to make a more robust app for an musical artist. Thus far, it involves segues from a "menu" ViewController to his Bio, Show Times, and "Listening Room" etc. Thus far, I...

iOS audio controls not working with singleton

ios,objective-c,avaudioplayer,mpnowplayinginfocenter
I'm trying to use a class to manage a global AVAudioPlayer instance, but I can't get the lock screen controls to appear. The class subclasses UIResponder, but no matter what I try lock screen controls don't appear. Client classes use - (void)setUrl:(NSURL *)url withTitle:(NSString *)title to load audio and playAudio...

Using NSURLSession to play remote audio, code critique

ios,avaudioplayer,nsurlsession
First, to avoid posting a great deal of code on here, I have created a very basic example of what I am after - https://github.com/opheliadesign/AudioTest. I am brand new to iOS development and I'm having a little trouble understanding the best way to load and play a static MP3 file...

AVAudioPlayer stop all sounds playing on different view controllers

ios,objective-c,iphone,avaudioplayer
I've an app with 3 view controllers. The first one generate a 5min track and when it goes to second view it keeps on playing in setVolume:2.0 and same goes for 3rd view controller.But on third ViewCOntroller there is a UIButton that re generate the first ViewController. And when it...

AVAudioRecorder not saving recording

ios,objective-c,audio,avaudioplayer,avaudiorecorder
I am making an iOS game. One of the things I need to do is to allow the user to make a quick little audio recording. This all works, but the recording is only temporarily saved. So when the user closes the app and reopens it, the recording should be...

iPhone - get amplitude of audio at current point

ios,objective-c,iphone,avaudioplayer
First off: I don't know much about audio processing. I know with Core Audio, you can get the info about a playing track. My goal is to have a node in SpriteKit with the current amplitude/loudness of the current song from iTunes being its scale (say, scale should be at...

How to Use Constants in Swift: AVAudioSessionInterruptionNotification

swift,avaudioplayer
This is my working code in Swift. The issue is that I'm using UInt as an intermediary type. func handleInterruption(notification: NSNotification) { let interruptionType = notification.userInfo?[AVAudioSessionInterruptionTypeKey] as! UInt if (interruptionType == AVAudioSessionInterruptionType.Began.rawValue) { // started } else if (interruptionType == AVAudioSessionInterruptionType.Ended.rawValue) { // ended let interruptionOption = notification.userInfo?[AVAudioSessionInterruptionOptionKey] as! UInt...

AVAudioPlayer not playing long sounds?

ios,audio,avaudioplayer
I have a series of sound files ranging from 0.3s to 3.0s. When trying to play with AVAudioPlayer, I get nothing, unless I add a sleep(4) call after to ensure the sound can play. Really weird. Apart from that, no errors with the error param that gets passed in, and...

Check if mp3 is playable in swift

ios,objective-c,swift,mp3,avaudioplayer
I'm trying to download & play remote mp3s. Basically: User clicks the mp3, Download starts on background and then, when it's possible, the playback starts. Everything works almost fine - the download is performed by AFHTTPRequestOperation which is downloading the mp3 directly into a file and I get progress updates...

Why the AVAudioPlayer var equals nil? - Swift

swift,null,avaudioplayer,nsbundle
This is my function: func playMusic(filename :String!) { var playIt : AVAudioPlayer! let url = NSBundle.mainBundle().URLForResource(filename, withExtension: nil) if url == nil { println("could not find \(filename)") return } var error : NSError? playIt = AVAudioPlayer(contentsOfURL: url, error: &error) if playIt==nil { println("could not create audio player") return } playIt.numberOfLoops...

Need help streaming Audio from URL using AVAudioPlayer iOS

ios,xcode,audio,stream,avaudioplayer
I am using twilio to create a phone app. I have a link to a voicemail and I am trying to play the voicemail from a control in a tableview. Since I have never streamed audio before I decided to simplify everything and just try to stream audio from any...

How does Soundcloud app skip to next track so fast?

ios,api,networking,avaudioplayer,soundcloud
I'm building my first app and it's a Soundcloud client. Right now, everytime a track is selected to play, I have to go on and do a NSURLSessionDataTask fetch to get the binary data, but this takes a long time. And when I skip, to the next track, I have...

Make a playlist (start next song) in swift

ios,swift,avfoundation,avaudioplayer,playlist
I have created a sound player in swift with AVFoundation. I am trying to start the next song in array when the playing song is finished. I was trying to implement this code if (audioPlayer.currentTime >= audioPlayer.duration){ var recentSong = songPlaylist[selectedSongNumber + 1] audioPlayer = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(recentSong, ofType: "mp3")!),...

Found nil-optional value with NSBundle Audioplayer [duplicate]

swift,avaudioplayer
This question already has an answer here: Converting PathForResource To String Returning nil Swift 2 answers When I am initialising a AVAudio player I am getting a found nil error. The music file is contained within a folder called 'Sounds'. fatal error: unexpectedly found nil while unwrapping an Optional...

Check if AVAudioPlayer is playing

swift,avaudioplayer
I've been trying to check if the AVAudioPlayer is currently playing, but when I try to do it in anyway it crashes. I'm using stop button to stop the audio but when there is no audio playing it crashes. How is it possible to check it in my stopaudio function...

Lower volume of AVAudioPlayer sound

ios,cocoa,audio,avaudioplayer
I have a background song that I use on an infinite loop while my app is in use. Except that the sound/volume is too high... I'd like it to be played at half the volume... This is how I load the music: //background music for in-game loop backgroundLoop = [[NSBundle...

Why is there a lag in my game everytime my sound is being played in swift?

ios,swift,avaudioplayer
The sound plays everytime I tap the screen but there is a slight hiccup in the game where you could see it lag the screen. How would I fix this? class level1: SKScene, SKPhysicsContactDelegate, GKGameCenterControllerDelegate { var jumpSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("tapsound", ofType: "wav")!) var jumpAudioPlayer = AVAudioPlayer() override func didMoveToView(view:...

Objective C protocol method is not called

objective-c,singleton,protocols,avaudioplayer
I have created singleton class for AVAudioPlayer. I am able to call the methods in the class and everything works fine. When the song finishes,the method (void)audioPlayerDidFinishPlaying is called which in turn suppose to call the method ' processSuccessful' in my downloadPlay.m class. But, it is not calling the method...

expression result unused on for loop

ios,objective-c,audio,for-loop,avaudioplayer
I've spent more or less most of they day working out how to play an audio file after another audio file has completed playing. I have tried the audioPlayerDidFinishPlaying which I had limited success with as it played the second audio file when other audio files played. So it played...

Swift - AVAudioPlayer still playing sound when device is on silent?

ios,swift,xcode6,avaudioplayer,silent
I am making a fairly basic app and have been exploring the use of AVAudioPlayer to play sound in my app, but I am having an issue where it plays sound even when the device is on silent. This is the code I am using: var audioPlayer = AVAudioPlayer() Then...

AVAudioPlayer wont play sound when called in other swift file

ios,swift,audio,avaudioplayer
I have two swift files - my ViewController:UIViewController and AudioPlayer:AVAudioPlayer. My AudioPlayer file has this function func seaGullSound() { var tmp = AVAudioPlayer() var seaGullSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Gulls", ofType: "mp3")!) AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil) AVAudioSession.sharedInstance().setActive(true, error: nil) var error:NSError? tmp = AVAudioPlayer(contentsOfURL: seaGullSound, error: &error) tmp.prepareToPlay()...

freestreamer can not resume play music after call end when app in background(have no sound actually)

ios,music,avaudioplayer,background-music
i try to use freestreamer to play music, a call coming when app in background, the music can stop, but if the call end(CTCallStateDisconnected), the music can not resume again, it can catch the status when the call end(AVAudioSessionInterruptionTypeEnded) in the FSAudioStream function which named } else if ([interruptionType intValue]...

resuming AVAudio playback after moving between ViewControllers - iOS

ios,objective-c,avaudioplayer
in my project i have background music playing in my viewDidLoad, i also have another viewController and when i go to ViewController2 the audio pauses using the [player pause]; method which is called in the viewWillDisappear. my problem is that when i move back to ViewController1, the audio starts over...

can AVAudioPlayer trigger events on predefined intervals?

swift,ipad,avfoundation,avaudioplayer
I need to make views visible at fixed time while running a MP3 audio. I am using Swift. Any suggestions?

AVAudioPlayer on OS X not playing any sound

objective-c,osx,cocoa,avaudioplayer
I'm trying to play a sound using AVAudioPlayer on os x (not iOS!). I'm using the following code: AVAudioPlayer *player; NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; player = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error:&err]; if( err ){ NSLog(@"Failed with reason: %@", [err localizedDescription]); } else{...

Concatenate two audio files in Swift and play them

swift,audio,concatenation,avaudioplayer,wav
I try to concatenate .wav audio files in swift. Here is my code : func merge(audio1: NSURL, audio2: NSURL) { var error:NSError? var ok1 = false var ok2 = false var documentsDirectory:String = paths[0] as! String //Create AVMutableComposition Object.This object will hold our multiple AVMutableCompositionTrack. var composition = AVMutableComposition() var...