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
17
votes
2 answers

Why do the Lock Screen audio controls disappear when I pause AVAudioPlayer?

I'm using an instance of AVAudioPlayer to play an audio file. The app is configured to play audio in the background and an appropriate audio session is set. I am also successfully receiving remote control events. Here's the code: #import…
maml
  • 594
  • 3
  • 11
17
votes
3 answers

AVAudioPlayer with external URL to *.m4p

My Problem is the following. I got this code and i guess a corrupt NSURL since the AVAudioPlayer is nil after initializing: NSString *dummyURLString = @"http://a825.phobos.apple.com/us/r2000/005/Music/d8/a8/d2/mzi.jelhjoev.aac.p.m4p"; NSError…
tommy
  • 173
  • 1
  • 1
  • 5
16
votes
3 answers

Audio Metering levels with AVPlayer

Is there a way to have the audio metering levels from the AVPlayer class? I know that AVAudioPlayer does that, but it doesn't play streamed http .m3u8 urls , like AVPlayer does.
neowinston
  • 7,584
  • 10
  • 52
  • 83
16
votes
4 answers

Swift 3 sound play

Ok I have looked into this and have tried many different ways to play a sound when a button is clicked. How would I play a sound when a button is clicked in swift 3? I have my sound in a folder named Sounds and the name is ClickSound.mp3
shane
  • 342
  • 1
  • 5
  • 28
16
votes
8 answers

Play background music in app?

I want the user to be able to open the app and have music start playing. I want the user to be able to go any view controller and return back to the initial one without the music stopping. I want it to loop indefinitely. I have tried to put in the…
user4984255
16
votes
0 answers

Detect ring/silent switch position change

I'm working on an app for which I would like to: respect the ring/silent switch when playing audio, and display an icon indicating that sound is muted when the ring/silent switch is set to silent. Requirement 1 is easy: I'm using…
ravron
  • 11,014
  • 2
  • 39
  • 66
16
votes
2 answers

Are there any other iOS system sounds available other than 'tock'?

I have implemented an alternative keyboard on my first iPhone app. I would like to play a sound when a button is pressed. The default click sound when the standard keyboard is pressed would be fine, but I don't know how to get that sound. In this…
Dale Dietrich
  • 7,196
  • 4
  • 21
  • 25
15
votes
2 answers

Implementing and Troubleshooting Background Audio in iOS

There are a lot of questions relating to background music playback in iOS on StackOverflow. None fully explore all edge cases, the aim of this question is to be the final word in background audio question on iOS Definitions & Assumptions All…
Richard Stelling
  • 25,607
  • 27
  • 108
  • 188
14
votes
6 answers

How to record and play sound in iPhone app?

I tried using AVAudioSession and AVAudioPlayer to record and play sounds respectively but the sound volume is very low. I tried putting volume value of AVAudioPlayer to 1.0 and more but didn't help much. What could be my other options to record…
Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
14
votes
1 answer

AVAudioEngine crashes when I unplug headphones during a call

Here is what I see in the log: 16:33:20.236: Call is Dialing 16:33:21.088: AVAudioSessionInterruptionNotification 16:33:21.450: AVAudioSessionRouteChangeNotification 16:33:21.450: ....change reason CategoryChange 16:33:21.539:…
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
14
votes
7 answers

OSStatus error 2003334207 when using AVAudioPlayer

I am trying to play an MP3 file (works when played via VLC/iTunes) when a button is pressed. Here is my code: var audioPlayer: AVAudioPlayer! @IBAction func playEpisode(sender: AnyObject) { println("now playing") let indexPath =…
user2747220
  • 863
  • 3
  • 12
  • 31
13
votes
3 answers

The Mute Button Won't Mute AVAudioPlayer

I need to loop play a .caf file in my iPhone app. The AVAudioPlayer looks promising. But there's one problem. It won't stop or mute even if I pressed the mute button on the iPhone. And I understand that there would be no way to programmatically find…
Di Wu
  • 6,436
  • 3
  • 35
  • 51
13
votes
2 answers

Listen to volume button presses the correct way (iOS 15)

I have used NotificationCenter.default.addObserver(self, selector: #selector(volumeChanged(_:)), name: NSNotification.Name(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"), object: nil) in the past to listen to volume control…
aaaav
  • 151
  • 9
13
votes
1 answer

iOS 12.4 AVAudioRecorder.record is returning false when app is in the background

First of all, this error only occurs in the latest 12.4 release on iOS. The issue does NOT occur in the simulator and must be run on a device. The issue is that the call to record on the AVAudioRecorder is returning false once the app goes into…
JeffP
  • 187
  • 1
  • 7
13
votes
2 answers

Is there any relationship between an AVAudioEngine and an AVAudioSession?

I understand that this question might get a bad rating, but I've been looking at questions which ask how to reroute audio output to the loud speaker on iOS devices. Every question I looked at the user talked about using your AVAudioSession to…
Logan
  • 1,047
  • 10
  • 33