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
20
votes
4 answers

AVAudioRecorder & AVAudioPlayer with iOS 7 not working properly

i'm having some issue with AVFoundation framework. I wrote a demo app to record audio, play it, and calculate decibels, with iOS 6. It both worked with iOS simulator built-in xcode 4.6.3 and my iPhone with iOS 6.1.3 Now i've update xcode to version…
ace_ventura
  • 468
  • 1
  • 4
  • 14
19
votes
4 answers

iOS 13.1 Crash in AVAudio Player

My App is crashing on iOS 13.1 when i trace a issue then found App is crashing because of AVAudioPlayer. Below Is My Player Setup. if let wrongURL = Bundle.main.url(forResource: "wrongAudio", withExtension: "mp3") { do { …
Rakesh Patel
  • 1,673
  • 10
  • 27
19
votes
4 answers

MP3 playing using AVAudioPlayer not working on device

I am testing my app on my 3GS iPhone with iOS 4.2 I am using the following code which plays a sound in my IBAction. It works perfectly in the simulator (both iPad and iPhone) - I hear the sound. NSString *pathToMusicFile1 = [[NSBundle mainBundle]…
Matt Facer
  • 3,103
  • 11
  • 49
  • 91
19
votes
5 answers

How to customize MPVolumeView?

I have tried many methods to implement a regular UISlider and control the device volume, but it's all Native-C functions which results in many untraceable bugs. I tried the MPVolumeView it works like charm, it even controls the device volume even…
mohdajami
  • 9,604
  • 3
  • 32
  • 53
19
votes
2 answers

Do an action when a sound has finished playing in AVAudioPlayer?

I am using the AVAudioPlayer framework, and I have several sounds that play one at a time. When a sound is finished playing, I want the application to do something. I tried to use audioPlayerDidFinishPlaying to do the action at the end of the first…
Evelyn
  • 2,588
  • 3
  • 22
  • 47
18
votes
2 answers

Entering background on iOS4 to play audio

The documentation is rather poorly written when talking about playing audio in the background. It gives the impression that all you have to do to continue playing the audio that you are currently playing is to just add a key/value pair to the…
iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
18
votes
7 answers

AVAudioPlayer working in Simulator, but not on device

My mp3 playing code is: NSError *error; soundObject = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:audioPathString] error:&error]; if (soundObject == nil) NSLog(@"%@", [error description]); soundObject.delegate =…
cannyboy
  • 24,180
  • 40
  • 146
  • 252
18
votes
4 answers

iPhone AVAudioPlayer stopping background music

So I've just noticed that on my iPod Touch, when my app triggers a short wav file to play using AVAudioPlayer, the music gets paused. Is this normal? I can't find any reference to this, and it seems like it would be noted somewhere. Is there a way…
Kenny Winker
  • 11,919
  • 7
  • 56
  • 78
18
votes
3 answers

AVAudioPlayer resetting currently playing sound and playing it from beginning

I'm having an issue using AVAudioPlayer where I want to reset a player if it's currently playing and have it play again. I try the following with no luck: The sound plays once but then the second time i select the button it stops the sound, the…
Dougnukem
  • 14,709
  • 24
  • 89
  • 130
17
votes
1 answer

AVFoundation: Video to OpenGL texture working - How to play and sync audio?

I've managed to load a video-track of a movie frame by frame into an OpenGL texture with AVFoundation. I followed the steps described in the answer here: iOS4: how do I use video file as an OpenGL texture? and took some code from the GLVideoFrame…
j00hi
  • 5,420
  • 3
  • 45
  • 82
17
votes
1 answer

Record Video and play audio at same time ios

I want to record video and play audio simultaneously. when start recording video, preloaded audio start play and when stop video recording, audio also stops playing. I tried to record Video by using third party library "SwiftyCam"…
17
votes
2 answers

AVFAudio playback crash on iOS 10

I've got an app with a very basic audio component: a looping set of background songs played with an AVAudioPlayer (song filenames stored as an array). Everything has been working fine for months, but iOS 10 is crashing for a significant number of my…
Nerrolken
  • 1,975
  • 3
  • 24
  • 53
17
votes
3 answers

How to connect the audio to bluetooth when playing using AVPlayer

I am playing the audio from an url using AVPlayer, but when the iPhone is connected to a Bluetooth device it is not playing via Bluetooth, how to play via Bluetooth if it is connected, i see some posts in SO, but none of those are clearly explained.…
Sudheer Kumar Palchuri
  • 2,919
  • 1
  • 28
  • 38
17
votes
7 answers

IOS 8 Swift AVAudioPlayer play remote audio (wowza server)

I am not an IOS programmer but I need a simple app to play an audio stream from a wowza server. Here is my code, I get no errors but also no audio. Any guidances or help? import UIKit import AVFoundation class ViewController:…
David Turton
  • 385
  • 2
  • 5
  • 15
17
votes
4 answers

How to do screen mirroring using AirPlay from the application (not from control centre) in iOS?

I am using MPVolumeView to show AirPlay button. I need to show a custom wallpaper to Apple TV through mirroring with audio. Audio is playing properly on Apple TV but wallpaper image is not showing. I am using AVAudioController for playing audio. I…
Mukesh2421
  • 191
  • 1
  • 6