avaudioplayer

The Mute Button Won't Mute AVAudioPlayer

≡放荡痞女 提交于 2019-12-03 02:46:48
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 out whether that mute button is pressed or not in iOS 5. So, what I need to know might be some properties about AVAudioPlayer or AVAudioSession. Or, perhaps, I may need to consider other libraries to loop playing my .caf file. Any idea? I realized it was because I had this line of code [[AVAudioSession sharedInstance] setCategory:

Routing iPhone Audio Sound

放肆的年华 提交于 2019-12-03 00:39:22
I have an app which does listen and play sound at the same time. By default, the sound output goes through the earphone. So I use the following code to route it through the speaker: UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride); This works fine. But now, I'd like to route the sound through the headphones when headphones or external speakers are attached. How would I achieve that? Also ideally all other sound (i.e. music etc.) should mute when the app

Playing audio with controls in iOS

梦想与她 提交于 2019-12-03 00:25:29
I've made an app with tab bar,nav bar and table view . In the table view you can choose to listen to some audio. New view opens and there I have some controls like: play,pause,volume slider, progress slider, label with the current time. It works, but not perfect. I can play the audio, I can pause the audio, I can also use the slider to skip forward or back. But now: When I hit the Back button on the navbar, the song keeps playing. That's ok, but when I go back to the view again, the timer and the slider reset themselves. I can't pause the song, just need to wait util it stops playing. Also,

Xcode stops on prepareToPlay

余生颓废 提交于 2019-12-02 21:26:34
Using AVAudioPlayer to add sound to a working application, it stops / hangs on prepareToPlay. Note it also stops / hangs on play. Hitting "Continue program execution" several times makes the application resume. This problem only occurs when running the program in the simulator. Using Xcode 4.6 Code Snippets: ViewController.h #import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface ViewController : UIViewController <AVAudioPlayerDelegate> @end ViewController.m #import "ViewController.h" @interface ViewController () { } @property (nonatomic, strong) AVAudioPlayer *audioPlayer;

Make AVAudioPlayer play a music file through phone call (ear) speaker

ぃ、小莉子 提交于 2019-12-02 20:08:23
问题 I want to play a music file through ear speaker, What I am doing now is: In viewDidLoad method :::: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [[AVAudioSession sharedInstance] setActive: YES error: nil]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; Initializing music file in viewDidLoad :::: musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"1985_Ring_" ofType:@"wav"]]; click = [[AVAudioPlayer alloc

Using Apple's new AudioEngine to change Pitch of AudioPlayer sound

烂漫一生 提交于 2019-12-02 19:38:40
I am currently trying to get Apple's new audio engine working with my current audio setup. Specifically, I am trying to change the pitch with Audio Engine, which apparently is possible according to this post . I have also looked into other pitch changing solutions including Dirac and ObjectAL, but unfortunately both seem to be pretty messed up in terms of working with Swift, which I am using. My question is how do I change the pitch of an audio file using Apple's new audio engine. I am able to play sounds using AVAudioPlayer, but I am not getting how the file is referenced in audioEngine. In

Swift 3 sound play

对着背影说爱祢 提交于 2019-12-02 19:18:25
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 User below this function //MARK:- PLAY SOUND func playSound() { let url = Bundle.main.url(forResource: "ClickSound", withExtension: "mp3")! do { player = try AVAudioPlayer(contentsOf: url) guard let player = player else { return } player.prepareToPlay() player.play() } catch let error as NSError { print(error.description) } } first import AudioToolbox import

How do I fastforward using AVAudioplayer while hearing the music?

ぐ巨炮叔叔 提交于 2019-12-02 19:08:04
问题 I got it to fast forward but I would like to hear the music when its fast forwarding. How would I be able to do this? Here is the code I have: if node.name == "left" { var time = musicPlayer.currentTime time += 1.0 musicPlayer.enableRate = true musicPlayer.rate = 2.0 if time > musicPlayer.duration { } else { musicPlayer.currentTime = time } } 回答1: Have a look at the rate property on AVAudioPlayer This property’s default value of 1.0 provides normal playback rate. The available range is from 0

iOS 7 : simple audio controls with AVAudioPlayer?

為{幸葍}努か 提交于 2019-12-02 17:21:08
I just begun to code iOS apps with xCode and it's not very easy nor intuitive to find how things work. I'm very new into this and my app goes on very slowly ^^. Anyway, I'm now trying things on iOS7, at least. I managed to create dynamic tables with customs cells and dynamic height but now I don't find any solution to my problem... Maybe I didn't search at the right place... anyway. I have an audio playing, thanks to these lines: NSString *path = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"mp3"]; AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL

iOS 7 SDK not abiding background audio

断了今生、忘了曾经 提交于 2019-12-02 16:57:17
I have done a lot of research, both on Google and StackOverflow. All the answers I found do not work in iOS 7. I started writing fresh app in iOS 7 SDK with Xcode 5. All I'm trying to do is play audio in the app from a file stored in the app bundle (not from the Music library). I want to have audio played in background and controlled when screen is locked (in addition to Control Center). I set the APPNAME-Info.plist key, UIBackgroundModes , to audio . It is not handling things in the app delegate; everything is done inside the ViewController @interface ViewController : UIViewController