Showing posts with label avaudioengine. Show all posts
Showing posts with label avaudioengine. Show all posts

Friday, October 27, 2017

AVAudioEngine Xamarin.iOS not catched exception engine required running

Leave a Comment

I'm using Xamarin.iOS for an application using AVAudioEngine.

Sometimes I get this exception :

AVFoundation_AVAudioPlayerNode_Play Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning()'

This point to my code:

private void PlayAudio() {     try     {         NSError err;         if (Engine.StartAndReturnError(out err))         {             foreach (var audioTrack in _dicPlayerNodes)             {                 audioTrack.Value.Play();             }         }         else         {             Messenger.Publish(new AudioErrorMessage(this) { Platform = "IOS", Code = Convert.ToInt32(err.Code), Message = err.LocalizedDescription ?? err.Description });              _exceptionHandlerService.PostHockeyApp(new Exception($"{err.Code} {err.Description}"));         }     }     catch (Exception ex)     {         _exceptionHandlerService.PostExceptionAsync(ex).Forget();     } } 

I don't understand how is it possible to have this exception that engine is not running, because in my code I Start it and get error if it failed to start ... Then play it.

Also I have a try catch that's not working in this case :( so my applicaton just crashed.

Any advices or idea ?

I comes to this thread but it doesn't help me to understand: https://forums.developer.apple.com/thread/27980

versions:

  • IOS version : 10.3.3

  • Device: ipad 2

  • Xamarin.ios: 11.2.0.11

Thanks

0 Answers

Read More

Friday, March 11, 2016

SKAudioNode() crashes when pluggin in/out headphones

Leave a Comment

I am using a SKAudioNode() to play background music in my game. I have a play/pause function and everything is working fine until I plug in my headphones. There is no sound at all and when I call the pause/play function I get this error

AVAudioPlayerNode.mm:333: Start: required condition is false: _engine->IsRunning() com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning()

Does anyone knows what this means?

Code:

import SpriteKit  class GameScene: SKScene {  let loop = SKAudioNode(fileNamed: "gameloop.mp3") let play = SKAction.play() let pause = SKAction.pause() var isPlaying = Bool()  override func didMoveToView(view: SKView) {       loop.runAction(play)     isPlaying = true     self.addChild(loop) }  override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {     _ = touches.first as UITouch!      for _ in touches {         if isPlaying {             loop.runAction(pause)             isPlaying = false         } else {             loop.runAction(play)             isPlaying = true         }      } } } 

1 Answers

Answers 1

I was not able fix it, but by using AVAudioPlayer() I found a good workaround. Thank you all for supporting me!

import SpriteKit import AVFoundation  class GameScene: SKScene {         var audioPlayer = AVAudioPlayer()        override func didMoveToView(view: SKView) {                 initAudioPlayer("gameloop.mp3")             }      override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {                 _ = touches.first as UITouch!         for _ in touches {             toggleBackgroundMusic()                     }             }      func initAudioPlayer(filename: String) {                 let url = NSBundle.mainBundle().URLForResource(filename, withExtension: nil)         guard let newURL = url else {             print("Could not find file: \(filename)")             return         }         do {             audioPlayer = try AVAudioPlayer(contentsOfURL: newURL)             audioPlayer.numberOfLoops = -1             audioPlayer.prepareToPlay()             audioPlayer.play()         } catch let error as NSError {             print(error.description)         }             }      func toggleBackgroundMusic() {                 if audioPlayer.playing {             audioPlayer.pause()         } else {             audioPlayer.play()         }             }     } 
Read More