avaudioplayer

(iOS) Why does AVAudioPlayer initWithContentsOfURL always fail with error code=-43

柔情痞子 提交于 2019-12-10 17:08:33
问题 NSString *songNameEscaped = [songName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *songURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", @"http://somerootpath/Music/", songNameEscaped]]; NSLog(@"songURL = %@", songURL); NSError *avPlayerError = nil; AVAudioPlayer *avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:songURL error:&avPlayerError]; if (avPlayerError) { NSLog(@"Error: %@", [avPlayerError description]); } else { [avPlayer play]; } If I

AVAudioPlayer getting wrong file duration iOS 10

北城余情 提交于 2019-12-10 16:13:16
问题 I am using AVAudioPlayer object to load audio file. I have checked with two browser 1) chrome is getting exact duration. while 2) Safari is getting wrong file duration. We have used the code as per below, let soundData = NSData(contentsOf: url as URL) self.player = try AVAudioPlayer(data: soundData! as Data) self.player.delegate = self let currentSecond = self.player.duration //Second Option we had tried. let assets = AVURLAsset(url: url as URL, options: [

AVAudioPlayer not playing audio Swift

China☆狼群 提交于 2019-12-10 15:56:56
问题 I am attempting to play a sound as an alert to the user of my app and I've looked at a few sources in trying to help me do this: AVAudioPlayer not playing audio in Swift (to help me solve the problem I am running into now, to no avail) Creating and playing a sound in swift (where I started originally) And these videos: https://www.youtube.com/watch?v=Kq7eVJ6RSp8 https://www.youtube.com/watch?v=RKfe7xzHEZk All of which are not giving me the desired outcome (the sound doesn't play). Here is my

How to play an AMR audio file?

[亡魂溺海] 提交于 2019-12-10 14:27:14
问题 I am trying to play an .amr file. func prepareAudio() { do { self.audioPlayer = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("welcome", ofType: "amr")!)) self.audioPlayer.play() } catch { print("Error") } } outPut ERROR: >aq> 327: AudioConverterNew from AudioQueueNew returned 'fmt?' io: 1 ch, 8000 Hz, Float32 client: 1 ch, 8000 Hz, 'samr' (0x00000000) 0 bits/channel, 0 bytes/packet, 2400 frames/packet, 0 bytes/frame 回答1: The AMR codec was

AVAudioPlayer lag when calling play

别等时光非礼了梦想. 提交于 2019-12-10 13:16:23
问题 I have set up an AVAudioPlayer object in viewDidLoad, as per the Apple guidelines, calling prepareToPlay as the last line in viewDidLoad (i have tried in awakeFromNib also). When i press my play button, there is a pause, as it would appear to load the file, then it plays. In audioPlayerDidFinishPlaying, i reload the player with a different sound, and when clicking play for a second time, the file plays instantly. What would cause the player to lag on the first play? Thanks. 回答1: The delay is

Playing an encrypted mp3 in iOS

谁说我不能喝 提交于 2019-12-10 12:06:49
问题 I have an aes encrypted mp3 file that I need to play in iOS; I can't decrypt the file to disk for security reasons, and I likely can't decrypt it to memory because of memory constraints. Is there a way to play an encrypted file directly, or to stream it to the player without loading it all into memory? I am really at a loss with this one, I don't even know where to begin... I'm using AVAudioPlayer to play files, but I'm guessing it's not flexible enough to do what I want. 回答1: I don't know

How can I fix “Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value” in Swift [duplicate]

ぐ巨炮叔叔 提交于 2019-12-10 12:00:44
问题 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 trying to add music to a game I created. But I am getting the error: "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value. I found another post on Stack Overflow (What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?), but I do not understand how this applies to my

Check if Audio is playing in the App

人盡茶涼 提交于 2019-12-10 11:55:10
问题 I've been working on that for 3 hours already, and i can't find a solution to it. I am using a 3rd Party library, that plays a sound for me, I am guessing they are using AVAudioPlayer playSound, and i want to know, if there is a way to know if my app is playing a sound. I don't have access to the 3rd Party library, and the property to play that sound is private. I've been trying AVAudioSession, but there's only two different ways to check if there is any sound playing, and unfortunately it

AVAudioPlayer doesn't work after 248 times

本小妞迷上赌 提交于 2019-12-10 11:35:59
问题 I am developing an application that involves clicking a button repeatedly, and I am giving an audio feedback for this click, a click wave file. it works fine, but I have a problem, after exactly 248 times, the sound is not played any more, the app doesn't crash however. and I get the following error: Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn't be completed. (NSOSStatusErrorDomain error -43.)" here is the code I am using, (pretty standard) //file.h AVAudioPlayer

AVAudioSession reactivation issue

Deadly 提交于 2019-12-10 10:52:44
问题 I am getting the following error: [0x19bf89310] AVAudioSession.mm:646: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session. I have read through this post: iOS8 AVAudioSession setActive error however the solution there did not solve my problem. which is: small application (game) audio background music handled in AudioHelper.swift additional 'blip' sounds played with