AVAudioPlayer.play() does not play sound
Why doesn’t the following code play a sound? It returns “true” for play(), but I cannot hear anything.
let path = "/Users/account/Music/sound.mp3"; let fileURL = NSURL(fileURLWithPath: path) var Player = AVAudioPlayer(contentsOfURL:fileURL, error:nil); Player.delegate = self; Player.prepareToPlay(); Player.volume = 1.0; var res = Player.play(); println(res);
If I use the following code instead, I can hear the sound.
var inFileURL:CFURL = fileURL!; var mySound = UnsafeMutablePointer<SystemSoundID>.alloc(sizeof(SystemSoundID)); AudioServicesCreateSystemSoundID(inFileURL, mySound); AudioServicesPlaySystemSound(mySound.memory)
- OS X Yosemite 10.10.3
- Xcode 6.2
- How to get AVAudioPlayer output to the speaker
- save the audio file in the background
- sound is not playing when node is touched in spritekit swift
- SKAction playSoundFileNamed doesn't work after receiving two consecutive phone calls
- Playing Raw pcm audio data coming from NSStream
- What does this gdb output mean?
Solutions Collect From Internet About “AVAudioPlayer.play() does not play sound”
The problem is that
Player, your AVAudioPlayer, is a local variable. So it goes out of existence immediately – before it can even start playing, let alone finish playing.
Solution: make it a property instead, so that it will persist.
- SQLite3 error – iOS
- How to set accuracy and distance filter when using MKMapView
- Pass data from tableview to tab bar view controller in Swift.
- How to fall back to marketplace when Android custom URL scheme not handled?
- NSSearchField: How to hide the icon (lupe)
- What's the difference between `-fembed-bitcode` and BITCODE_GENERATION_MODE?
- Rotate Portrait to Landscape in pdfreader in ios6 and ios7
- How can I link to my app in the App Store (iTunes)?
- Swift 3 – Loading a previously saved audio file as base64 string
- On a jailbroken iPhone, how can I run commands as root?
- How to get userInfo JSON Value inside didReceiveRemoteNotification
- Phonegap – navigator.app.backHistory() not working on HTML back button
- How to restrict special characters in UITextField except dot and underscores?
- What is the best practice for updating UI from Core Audio Callback?
- iOS blured overlay view