avaudioplayer

AVAudioPlayer refuses to play anything, but no error, etc

孤街醉人 提交于 2019-12-13 08:18:51
问题 This is the simplest possible AVAudioPlayer code, and it's just failing to play anything back. No errors, nothing in the console at all, the file is definitely being found as if I change the URL string to something which isn't there, I do get a crash. What am I doing wrong here? I've tried it with and without the delegate, as well as with and without prepareToPlay, and I can't get anything out. I've tried various sound files, too. Really tearing my hair out on this one! @implementation

AVAudioPlayer not responding in the background

白昼怎懂夜的黑 提交于 2019-12-13 07:13:53
问题 i'm playing audio in the background when my app receive voip notification. But AVAudioPlayer acting weird and sometimes play the audio and sometimes not without any error. thats how i play: func playAudio() { // Set the sound file name & extension let alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("testAudio", ofType: "wav")!) // Play the sound do { try audioPlayer = AVAudioPlayer(contentsOfURL: alertSound) audioPlayer.delegate = self if (audioPlayer.prepareToPlay()

AVAudioPlayer isPlaying always return null

自古美人都是妖i 提交于 2019-12-13 06:42:31
问题 I'm experiencing an odd problem with AVAudioPlayer class. Everytime I try to access one of it's properties they are null. // Get the file path to the song to play. NSString *filePath = [[[NSBundle mainBundle] pathForResource:pSound.fileName ofType:pSound.fileType] retain]; // Convert the file path to a URL. NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath]; NSError* err; //Initialize the AVAudioPlayer self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:

NSTimer creating a pulse effect in AVAudioPlayer and UIAnimation

落爺英雄遲暮 提交于 2019-12-13 06:03:48
问题 I've made a sound app with a UIVIew .png image ( mouthMeter ) whose alpha I would like to dim according to the averagePowerForChannel coming out of AVAudioPlayer . The alpha is being changed via updates from an NSTimer , meterTimer , 12 times a second (to simulate 12 fps). I also have a second NSTimer , sliderTimer which is updating the position of a UISlider once every second. The dimming seems to be occuring, however there is a second effect of the alpha pulsing to fully-on (1.0). I can

Issue with playing music file during a phone calling iOS sdk

大城市里の小女人 提交于 2019-12-13 04:50:37
问题 I have two pieces of code: Code 1 - This is playing a music file via the in-ear speaker: NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"8Ocean.mp3"]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:tileDirectory]; NSError *error=nil; self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error]; if(!error) { [self.audioPlayer prepareToPlay]; UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;

Check if AVAudioPlayer is playing

微笑、不失礼 提交于 2019-12-13 04:32:23
问题 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 ? First I defined : var audioPlayer = AVAudioPlayer() I have stop button : func stopaudio(sender: AnyObject){ audioPlayer.stop() } I tried to check like this : if audioPlayer.playing{ audioPlayer.stop() } I am using the following code to

setting delegate to self throwing error in Swift [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-13 04:22:43
问题 This question already has answers here : What does “Fatal error: Unexpectedly found nil while unwrapping an Optional value” mean? (11 answers) Closed last year . I am currently working on code that disables a UIImageView while an AVAudioPlayer is playing. The AVAudioPlayer and the ImageView I want to disable are located in two different classes. I tried writing a delegate to have my two classes communicate but I keep on getting the error "Thread 1: Fatal error: Unexpectedly found nil while

ARKIT : SKVideoNode continue playing while node is out of scene, pause is not working

断了今生、忘了曾经 提交于 2019-12-13 03:46:54
问题 I am implementing a demo project using SceneKit and ARKit where i keep camera on some picture and play video from url. Everything works fine but i could not be able to stop previous video and it starts another video. Previous video plays on background. It happens sometimes when i switch image. My implementation is : @IBOutlet var sceneView: ARSCNView! var videosNames = [String]() var player = AVPlayer() var videoNode = SKVideoNode() In viewDidload, sceneView.delegate = self // Create a

Fatal error when trying to play audio in Swift

不问归期 提交于 2019-12-13 02:02:53
问题 Trying to play audio but keep receiving fatal error : unexpectedly found nil while unwrapping an Optional value Here is my code: import UIKit import AVFoundation class PlaySoundsViewController: UIViewController { var audioPlayer : AVAudioPlayer! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. if var filePath = NSBundle.mainBundle().pathForResource("movie", ofType: "mp3"){ var filePathURL = NSURL.fileURLWithPath(filePath) var audioPlayer =

AVAudioPlayer eliminating one second pause between sound files

◇◆丶佛笑我妖孽 提交于 2019-12-13 00:29:05
问题 I am using multiple instances of AVAudioPlayer to play multiple sound files in a succession. I am noticing that there is a roughly one second pause when two different sound files are played. Is it possible to eliminate this one second pause? I call [myPlayer prepareToPlay] for each player ahead of time already. 回答1: According to AVAudioPlayer documentation you could use playAtTime: for synchronized playing. Modified example would look like this: - (void) startSynchronizedPlayback {