avaudioplayer

check avaudioplayer's current playback time

故事扮演 提交于 2019-12-03 15:12:18
Is this the right way to check AVAudioPlayer's current playback time. [audioPlayer play]; float seconds = audioPlayer.currentTime; float seconds = CMTimeGetSeconds(duration); How I can code after [audioPlayer play]; that when currentTime is equal to 11 seconds then [self performSelector:@selector(firstview) withObject:nil]; and after firstview when currentTime is equal to 23 seconds [self performSelector:@selector(secondview) withObject:nil]; gregheo You could set up a NSTimer to check the time periodically. You would need a method like: - (void) checkPlaybackTime:(NSTimer *)theTimer { float

Soundcloud iOS API - playing sound from link

余生长醉 提交于 2019-12-03 14:55:23
问题 I want to play a public sound in my app using the Soundcloud API. After some searchs around the web, I find a way to do it, but I can't make my code works. Here's the code I tried to play a sound : NSString *publicTrackUrlString = @"https://soundcloud.com/miroslav-osipovic/the-cat-empire-the-lost-song"; NSString *urlString = [NSString stringWithFormat:@"%@?client_id=64a52bb31abd2ec73f8adda86358cfbf", publicTrackUrlString]; [SCRequest performMethod:SCRequestMethodGET onResource:[NSURL

IOS: Play sound while app in background

匆匆过客 提交于 2019-12-03 14:30:01
I working on a little app where i want the phone to play a sound file on an event from my location controller. The problem is when the App is in Background mode the AVAudioPlayer not start the Audio file but the code is scheduled, getting NSLog output. Another thing is it works in the simulator but not on the phone. Whys not? This is my code to play the file: - (void)tryPlayTaleSound:(NSString*)fileName { NSString *backgroundMusicPath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"]; NSURL *backgroundMusicURL = [NSURL fileURLWithPath:backgroundMusicPath]; NSError *error;

AVAudioPlayer with MPMusicPlayerController

不问归期 提交于 2019-12-03 13:21:10
问题 I have music playing within my application using a MPMusicPlayerController , using iPodMusicPlayer (also tried applicationMusicPlayer). When I play a sound using AVAudioPlayer my music from my MPMusicPlayerController will stop. Is there a way to have the MPMusicPlayerController and the AVAudioPlayer play sounds simultaneously? 回答1: Hey, found the solution on the web. Write these 2 lines somewhere, I did it in application:didFinishLaunchingWithOptions // Set sounds not to stop music [

Audio Session “Ducking” Broken in iOS 4…?

风流意气都作罢 提交于 2019-12-03 13:08:19
I've an app which uses the MPAudioPlayerController to access the iPod music library, and an AVAudioPlayer to overlay audio on top of the music. I've used this documentation as a guide. Specifically: Finally, you can enhance a category to automatically lower the volume of other audio when your audio is playing. This could be used, for example, in an exercise application. Say the user is exercising along to their iPod when your application wants to overlay a verbal message—for instance, “You’ve been rowing for 10 minutes.” To ensure that the message from your application is intelligible, apply

Reusing an AVAudioPlayer for a different sound

谁都会走 提交于 2019-12-03 13:03:02
I have an instance of AVAudioPlayer that will play several sounds. Is there a way to provide an AVAudioPlayer instance with a new sound, or do I have to create a new instance with initWithData:? zoul Reusing objects is usually a bad idea, generally try to have your objects as short-lived as possible. This reduces the number of possible states of your code and makes reasoning about it easier. (“Where did this value come from? Maybe it’s a leftover from the previous instance usage?” Yuck.) Only break this rule once you run into measurable problems. For further reading along this line of thought

Playing audio with controls in iOS

强颜欢笑 提交于 2019-12-03 10:48:22
问题 I've made an app with tab bar,nav bar and table view . In the table view you can choose to listen to some audio. New view opens and there I have some controls like: play,pause,volume slider, progress slider, label with the current time. It works, but not perfect. I can play the audio, I can pause the audio, I can also use the slider to skip forward or back. But now: When I hit the Back button on the navbar, the song keeps playing. That's ok, but when I go back to the view again, the timer and

Routing iPhone Audio Sound

拥有回忆 提交于 2019-12-03 10:08:39
问题 I have an app which does listen and play sound at the same time. By default, the sound output goes through the earphone. So I use the following code to route it through the speaker: UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride); This works fine. But now, I'd like to route the sound through the headphones when headphones or external speakers are attached.

How to Play system beep sound programatically in iPhone?Is it possible to play system sound without adding it to bundle resources

南楼画角 提交于 2019-12-03 08:25:16
Is it possible to play system beep alert sound.I do not want to add the sound file to my resource bundle and i want to access the apple system sounds and play it wherever needed. Try this AudioServicesPlaySystemSound(1103); to vibrate AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); For list of sounds http://iphonedevwiki.net/index.php/AudioServices 来源: https://stackoverflow.com/questions/18711983/how-to-play-system-beep-sound-programatically-in-iphoneis-it-possible-to-play-s

How to Make and Play A Procedurally Generated Chirp Sound

核能气质少年 提交于 2019-12-03 07:57:38
My goal is to create a "Chirper" class. A chirper should be able to emit a procedurally generated chirp sound. The specific idea is that the chirp must be procedurally generated, not a prerecorded sound played back. What is the simplest way to achieve a procedurally generated chirp sound on the iPhone? You can do it with a sine wave as you said, which you would define using the sin functions. Create a buffer as long as you want the sound in samples, such as: // 1 second chirp float samples[44100]; Then pick a start frequency and end frequency, which you probably want the start to be higher