avaudioplayer

Start playing sound in background on iOS?

随声附和 提交于 2019-11-30 14:53:05
I'm trying to do something similar to Tile.app . When it shows a notification, it plays a sound. That seems simple enough-- use UILocalNotification and include the sound file name. But local notifications limit sounds to no more than 30 seconds, and Tile's sound keeps playing for a whole lot longer than that. I expect it's looping, and it continues until I can't stand the noise any more. The sound also plays even if the phone's mute switch is on, which doesn't happen with local notifications. For these reasons, UILocalNotification appears to be out. I thought maybe I could post a text-only

How to build a Workout app on WatchOS with audio feedback?

廉价感情. 提交于 2019-11-30 14:39:46
I am building a very simple workout app on WatchOS: One of it functions is to give audio feedback during the training. I am able to play a file when the display is on, but when the display is dark, the watch doesnt play my file. Can some one look over my swift code and help my figuring out what I am missing? Here is my extensionDelegate.swift: var audioPlayer = AVAudioPlayer() class ExtensionDelegate: NSObject, WKExtensionDelegate { func applicationDidFinishLaunching() { let audioSession = AVAudioSession.sharedInstance() do { try audioSession.setCategory(AVAudioSessionCategoryAmbient, with:

IOS maximum volume level for AVAudioPlayer?

谁说胖子不能爱 提交于 2019-11-30 13:53:05
I use the AVAudioPlayer to play a .caf file. My problem is: it is not loud enough for my purpose. Since the ringer sound of the IPhone is much louder I was wondering how I can archive this volume. I already tried to manipulate the .caf file but with no real success. Any ideas? The code I use so far: AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: nil]; self.appSoundPlayer = newPlayer; [newPlayer release]; [appSoundPlayer prepareToPlay]; [appSoundPlayer setVolume: 0.8]; [appSoundPlayer setDelegate: self]; [appSoundPlayer play]; Edit: [appSoundPlayer setVolume

how to show seek track duration on control center

北慕城南 提交于 2019-11-30 11:09:55
问题 How do i pass the song info such as song name and track duration to control center. Player plays music fine and the play and pause control works fine though. Playing with apple's music app Playing with my app with the code below, how to pass song information in order to display it ? //AppDelegate -(void)setupAudio { // Set AVAudioSession NSError *sessionError = nil; [[AVAudioSession sharedInstance] setDelegate:self]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback

How to copy songs from iPod Library to app and play with AVAudioPlayer?

眉间皱痕 提交于 2019-11-30 10:32:45
问题 Though a duplicate but i want to play song using AVAudioPlayer from iPod Library. So Is it possible to copy iPod Library songs after copying it to app? I have one code which converts the song to caf format and then I am able to play using AVAudioPlayer . But Conversion takes too long time. So is there any other way I can do that? 回答1: The following code will read the ipod library song from its url and copy it to disk for use.. note this code wont work with m4as because the URLs from ipod

Issue with “try?” and AVAudioPlayer

余生颓废 提交于 2019-11-30 09:24:39
问题 I am having the following issue with AVAudioPlayer: import Foundation //Needed for dispatch_once_t import AVFoundation //Needed to play sounds class PlayStartSong { var song: AVAudioPlayer = AVAudioPlayer() var songStarted: Bool = false class var sharedInstance: PlayStartSong { struct Static { static var onceToken: dispatch_once_t = 0 static var instance: PlayStartSong? = nil } dispatch_once(&Static.onceToken) { Static.instance = PlayStartSong() } return Static.instance! } func prepareAudios(

Play/Pause with the same button [AVAudioPlayer]

女生的网名这么多〃 提交于 2019-11-30 09:24:13
How can I play a sound with an IBAction by pressing on a UIbutton once and pause it by pressing the button again using AVAudioPlayer ? Also I want to change the state of that UIButton when the sound is playing and when it's not. Here's my code: - (IBAction)Beat { if ([Media2 isPlaying]) { [Media2 pause]; [Button17 setSelected:NO]; } else { Path = [[NSBundle mainBundle] pathForResource:@"Beat" ofType:@"mp3"]; AVAudioPlayer *Media2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:Path] error:NULL]; [Media2 setDelegate:self]; [Media2 play]; [Button17 setSelected:YES]; } }

Detect ring/silent switch position change

僤鯓⒐⒋嵵緔 提交于 2019-11-30 08:55:45
I'm working on an app for which I would like to: respect the ring/silent switch when playing audio, and display an icon indicating that sound is muted when the ring/silent switch is set to silent. Requirement 1 is easy: I'm using AVAudioSessionSoloAmbient as my app's audio session category, so that my audio session will mute itself when the ring/silent switch is off. Requirement 2 seems considerably harder, because I need some sort of callback, notification, or KVO that will allow me to monitor the position of the switch, but Apple has made it clear that it is unwilling to offer an officially

AVAudioPlayer stops playing on screen lock even though the category is AVAudioSessionCategoryPlayback

半城伤御伤魂 提交于 2019-11-30 08:46:25
My app uses AVAudioPlayer to play through audio playlists. I haven't changed the code between iOS4.3 and iOS5. However, the audio on iOS5 pauses on a screen lock even though I've set the category to be AVAudioSessionCategoryPlayback. I've tested the code on iOS4.3 and iOS5 devices and this problem occurs on the iOS5 device. Has anyone else faced this problem? I'm at a loss since I don't even know where to start debugging this issue. My debugging started and ended with checking the AVAudioSessionCategory setting. The code where I'm doing it is: [[AVAudioSession sharedInstance] setDelegate: self

How to connect the audio to bluetooth when playing using AVPlayer

喜欢而已 提交于 2019-11-30 08:38:38
I am playing the audio from an url using AVPlayer, but when the iPhone is connected to a Bluetooth device it is not playing via Bluetooth, how to play via Bluetooth if it is connected, i see some posts in SO, but none of those are clearly explained. Below is my code. -(void)playselectedsong{ AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:urlString]]; self.songPlayer = player; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:[songPlayer currentItem]]; [self.songPlayer