avaudioplayer

Extract meter levels from audio file

烂漫一生 提交于 2019-12-21 03:33:53
问题 I need to extract audio meter levels from a file so I can render the levels before playing the audio. I know AVAudioPlayer can get this information while playing the audio file through func averagePower(forChannel channelNumber: Int) -> Float. But in my case I would like to obtain an [Float] of meter levels beforehand. 回答1: Swift 4 It takes on an iPhone: 0.538s to process an 8MByte mp3 player with a 4min47s duration, and 44,100 sampling rate 0.170s to process an 712KByte mp3 player with a 22s

Audio playing while app in background iOS

风流意气都作罢 提交于 2019-12-20 19:05:12
问题 I have an app mostly based around Core Bluetooth. When something specific happens, the app is woken up using Core Bluetooth background modes and it fires off an alarm, however I can't get the alarm working when the app is not in the foreground. I have an Alarm Singleton class which initialises AVAudioPlayer like this: NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:soundName ofType:@"caf"]]; self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

AVAudioPlayer time display

早过忘川 提交于 2019-12-20 14:46:16
问题 I have a simple mp3 playing through AVAudioPlayer and I want to be able to display how much time is left. I know the answer includes subtracting AVAudioPlayer.duration from AVAudioPlayer.currentTime but I don't know how to implement a function which calculates it while it's playing (like an onEnterFrame in Actionscript I guess). At present currentTime is static, i.e. zero. 回答1: I would go for an NSTimer. Schedule it to run every second while the media is played and so you can keep your UI

iOS 7 SDK not abiding background audio

人走茶凉 提交于 2019-12-20 08:21:37
问题 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

Cannot stop background music from within Game Scenes, Swift 3/Spritekit

白昼怎懂夜的黑 提交于 2019-12-20 07:22:06
问题 On XCODE 8/Swift 3 and Spritekit, i am playing background music (a 5 minute song), calling it from GameViewController's ViewDidLoad (from the parent of all the scenes, not from a specific GameScene), as I want it to play throughout scene changes without stopping. This happens without a problem. But my problem is, how do i stop the background music at will, when I am inside a scene? Say when user gets to a specific score on the game on the 3rd scene? As i cannot access the methods of the

MASSIVE AVAudioPlayer Memory Leaks

夙愿已清 提交于 2019-12-20 07:21:44
问题 I am using AVAudioPLayer to do the audio for my game. I have the following code in a method in a seperate class, which is called every time I want the 'boing' sound to play. Problem is, it leaks huge amounts of memory, to the point where the game becomes unplayable. Now i'm not releasing any of the pointers in the method, because at the time I only had one. But now I have 10 of these methods. What is the best way to release the pointers in tis case? (Yes, I have tried releasing straight after

AVAudioPlayer play file in Background

Deadly 提交于 2019-12-20 02:56:22
问题 I am developing music app in which app should be run in background. That is when user select file to play and he pressed home button then file should continue to play in background. I am using AVAudioPlayer. I tried this: **AppDelegate.m** - (void)applicationDidEnterBackground:(UIApplication *)application { UIApplication* app = [UIApplication sharedApplication]; NSAssert(self->bgTask == UIBackgroundTaskInvalid, nil); bgTask = [app beginBackgroundTaskWithExpirationHandler: ^{ dispatch_async

Play sound continuously onTouch()

≡放荡痞女 提交于 2019-12-20 02:54:28
问题 I want to play a gun shot sound continuously by onTouch. I am doing this for automatic gun sounds. So i have problem with there is delay in sound looping. which does not give real automatic gun sound effect. My main point is there should no delay when sound is playing again and again. My code is. public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == MotionEvent.ACTION_DOWN) { mediaPlayer = MediaPlayer.create(RipleFire.this, sounds

save the audio file in the background

懵懂的女人 提交于 2019-12-20 02:51:06
问题 I have an app that changes the pitch of the audio when the pitch button is selected, now i am using installTapOnBus to save the file but this method gets invocated after i press the pitch button therefore only part of the audio is saved, i want to save the whole audio no matter when the pitch button is selected, is there any way This method is used to play the audio -(void)playAudio { NSError *err = nil; audioEngine = [[AVAudioEngine alloc] init]; AudioFileplayer = [[AVAudioPlayerNode alloc]

AVPlayer Volume Control

独自空忆成欢 提交于 2019-12-19 18:50:23
问题 I want to create a button that mutes the audio from an AVPlayer. Why can´t I use .volume with AVPlayer, only with AVAudioPlayer? Is there another way to change the volume? e.g music.volume = 0.0; Thanks for your answers. 回答1: Starting in iOS 7, simply call: myAvPlayer.volume = 0; Otherwise, you'll have to use the annoying setAudioMix solution. I'm detecting support for this in my app as follows: if ([mPlayer respondsToSelector:@selector(setVolume:)]) { mPlayer.volume = 0.0; } else { NSArray