Questions tagged [avaudioplayer]

Apple’s AVFoundation framework includes AVAudioPlayer, an easy, feature rich, Objective-C based API for playing audio files.

An instance of the AVAudioPlayer class, called an audio player, provides playback of audio data from a file or memory.

Apple recommends that you use this class for audio playback unless you are playing audio captured from a network stream or require very low I/O latency. For an overview of audio technologies, see Audio & Video Starting Point and “Using Audio” in Multimedia Programming Guide.

Using an audio player you can:

  • Play sounds of any duration
  • Play sounds from files or memory buffers
  • Loop sounds
  • Play multiple sounds simultaneously, one sound per audio player, with precise synchronization
  • Control relative playback level, stereo positioning, and playback rate for each sound you are playing
  • Seek to a particular point in a sound file, which supports such application features as fast forward and rewind
  • Obtain data you can use for playback-level metering

Source: ADC - AVAudioPlayer Class Reference

2788 questions
108
votes
6 answers

AVAudioPlayer throws breakpoint in debug mode

Every time I load the app it stops as if I had set a breakpoint on this line: self.audioPlayer = [[[AVAudioPlayer alloc] initWithData:[dataPersister loadData:self.fileName] error:&outError] autorelease]; There's…
ThomasCle
  • 6,792
  • 7
  • 41
  • 81
74
votes
8 answers

Playing a sound with AVAudioPlayer

I'm trying to play a sound with AVAudioPlayer but it won't work. Edit 1: Still doesn't work. Edit 2: This code works. My device was in silent mode. import UIKit import AVFoundation class ViewController: UIViewController { var audioPlayer =…
user3722523
  • 1,740
  • 2
  • 15
  • 27
66
votes
8 answers

Are headphones plugged in? iOS7

Developing an app for an iPhone with audio files that need to be listened too through headphones. How do I check if headphones aren't plugged in so I can tell the user to plug in headphones. I have the following code from another thread but the…
4GetFullOf
  • 1,738
  • 4
  • 22
  • 47
63
votes
8 answers

Play sound on iPhone even in silent mode

I want to make an application which creates sound, music, or system sound when an iPhone is in silent mode. Is it possible to play any type of sound whether music or system tones when it is silent mode?
Pankaj Kainthla
  • 2,439
  • 5
  • 31
  • 61
51
votes
12 answers

AVAudioPlayer fade volume out

I have an AVAudioPlayer playing some audio (duh!) The audio is initiated when the user presses a button. When they release it I want the audio to fade out. I am using Interface builder...so I am trying to hook up a function on "touch up inside" that…
Jonathan
47
votes
8 answers

How do I start playing audio when in silent mode & locked in iOS 6?

End-user process Open app Switch on 'Silent Mode'. Press 'Lock-button' App can still START playing a sound after hours have passed, not playing any audio in the interim. Apps that do this A lot of alarm apps have manage to do this & I dont think…
Andres Canella
  • 3,706
  • 1
  • 35
  • 47
43
votes
9 answers

Slow start for AVAudioPlayer the first time a sound is played

I'm trying to eliminate startup lag when playing a (very short -- less than 2 seconds) audio file via AVAudioPlayer on the iPhone. First, the code: NSString *audioFile = [NSString stringWithFormat:@"%@/%@.caf", [[NSBundle mainBundle] resourcePath],…
John Biesnecker
  • 3,782
  • 2
  • 34
  • 43
40
votes
12 answers

Play music in the background using AVAudioplayer

I want to play music even if the app goes in background. I checked all stackoverflow links but none of them worked. Please help need to do it today. I had used following code:- NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Day…
leena
  • 689
  • 2
  • 7
  • 15
40
votes
11 answers

How to play mp3 audio from URL in iOS Swift?

I am getting mp3 url as a response of an API call. I want to play that audio, so how can I do that? here is my response { content = "En este primer programa se tratar\U00e1n asuntos tan importante como este y aquel sin descuidar un poco de todo…
Govind
  • 411
  • 1
  • 5
  • 11
34
votes
7 answers

UISlider to control AVAudioPlayer

I'm trying to implement a little function in my app. I am currently playing sounds as AVAudioPlayers and that works fine. What I would like to add is to control the sound's position (currentTime) with an UISlider: is there a simple way to do it ? I…
David Pollak
  • 367
  • 1
  • 3
  • 5
34
votes
11 answers

How to get AVAudioPlayer output to the speaker

I'm recording audio with AVAudioRecorder as seen in How do I record audio on iPhone with AVAudioRecorder? I then use AVAudioPlayer to play back the recording. However the sound is coming out of the ear speaker, not the loud speaker. How would I go…
dizy
  • 7,951
  • 10
  • 53
  • 54
33
votes
7 answers

Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?

I've tried using these methods in an attempt to detect that the Ring/Silent switch is active or not: How to programmatically sense the iPhone mute switch? AVAudioSession category not working as documentation dictates But on my iPhone 4, the "state"…
taber
  • 3,166
  • 4
  • 46
  • 72
29
votes
3 answers

AVAudioPlayer produces lag despite prepareToPlay() in Swift

Playing a very short sound (~0.5s) produces a hiccup (like a lag) in my SpriteKit iOS game programmed in Swift. In other questions, I read that I should prepareToPlay() the sound, which I did. I even used a variable (soundReady) to check if the…
Timme
  • 415
  • 4
  • 9
29
votes
3 answers

Supported Audio file formats in iPhone

What are the supported audio files formats in iPhone? If I want to play a 2 hour audio files , what is the best audio file format I should have in my App? Thanks
Biranchi
  • 16,120
  • 23
  • 124
  • 161
28
votes
5 answers

What do you use to play sound in iPhone games?

I have a performance-intensive iPhone game I would like to add sounds to. There seem to be about three main choices: (1) AVAudioPlayer, (2) Audio Queues and (3) OpenAL. I’d hate to write pages of low-level code just to play a sample, so that I would…
zoul
  • 102,279
  • 44
  • 260
  • 354
1
2 3
99 100