avaudioplayer

How can I stop AVAudioPlayer from repeating before it reaches the end of my data?

 ̄綄美尐妖づ 提交于 2019-12-11 02:25:05
问题 I'm playing looped sound with AVAudioPlayer by setting the numberOfLoops property to -1. And I want to control the loop rate programmatically, so I'm loading my audio data like this: NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Click" ofType:@"aif"]; NSMutableData *soundData = [NSMutableData dataWithContentsOfFile:soundFilePath]; And then changing its length before initializing the audio player: int loopDuration = .5; // seconds int desiredDataLength = loopDuration * 2 *

How do I get music to persist as I navigate from view to view?

让人想犯罪 __ 提交于 2019-12-11 02:22:55
问题 So, I have mastered the art of playing sounds/music using one view in iOS, but I am now trying to make a more robust app for an musical artist. Thus far, it involves segues from a "menu" ViewController to his Bio, Show Times, and "Listening Room" etc. Thus far, I created a an "AudioManager" class: import UIKit import AVFoundation import MediaPlayer class AudioManager: NSObject { let defaltSong = ["Hell&BackCaf/01 Black Sheep", "caf"] weak var delegate : PlayerDelegate? var musicPlayer1 =

How to convert FLAC file to wav file in ios?

£可爱£侵袭症+ 提交于 2019-12-11 02:16:37
问题 I want to create a audio player that support Flac format of audio files.For this i tried to implement the algorithm of flac to wav conversion which is as follow Please help me. All time it gives me error ERROR: initializing decoder: FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE static FLAC__bool write_little_endian_uint16(FILE *f, FLAC__uint16 x) { return fputc(x, f) != EOF && fputc(x >> 8, f) != EOF ; } static FLAC__bool write_little_endian_int16(FILE *f, FLAC__int16 x) { return write

How to play sounds in locked mode on iPhone

和自甴很熟 提交于 2019-12-11 02:08:06
问题 Everybody knows the standard procedure to keep your app alive, after the user pressed the lock button (silent sound). If I start a sound with AVAudioPlayer (before the iphone is locked), the sound plays till it's end (after locking). The app is still running. If I try to start another sound while the iPhone is locked, it will never get played. All the other things work as well but the sound doesn't. How can I play a sound while the iphone is locked? 回答1: If the problem is that your app is

No Sound When Trying to Play Audio (.wav) Files

孤街浪徒 提交于 2019-12-11 01:38:21
问题 I have a very simple class that can play a sound file with the following code: import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; public class Sound{ private Clip sound; public Sound(String location){ try{ sound = AudioSystem.getClip(); File file = new File(location); sound.open(AudioSystem.getAudioInputStream

AVPlayer Live stream how to get power for audio level metering

ぐ巨炮叔叔 提交于 2019-12-11 01:11:58
问题 I am trying to show a meter graph in my app which uses AVPlayer to stream live audio streams. I know for AVAudioPlayer there is a way as per: Trying to understand AVAudioPlayer and audio level metering which uses peakPowerForChannel But AVAudioPlayer doesn't work for audio streams. Is there something similar for AVPlayer? Or is there any other way I can get the power values from the AVPlayer? Code: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; if

Is it possible to use different volume levels for different players (AVAudio Player and MPMusicPlayer) while they are playing simultaneously?

不问归期 提交于 2019-12-11 00:13:22
问题 I need to set different volume levels for different players using AVAudio and MPMusic Players, I am playing both players but I do not know how to set different different volumes levels. Thank you, Madan Mohan 回答1: Say your avaudioplayer is named theAudio. To control that volume, say [theAudio.volume =//volume here]; Do the same for mpmusicplayercontroller. 来源: https://stackoverflow.com/questions/6409940/is-it-possible-to-use-different-volume-levels-for-different-players-avaudio-pla

iOS: How to play audio without fps drops?

你离开我真会死。 提交于 2019-12-10 23:39:57
问题 I am in the process of developing a game for iOS 9+ using Sprite Kit and preferably using Swift libraries. Currently I'm using a Singleton where I preload my audio files, each connected to a separate instance of AVAudioPlayer. Here's a short code-snipped to get the idea: import SpriteKit import AudioToolbox import AVFoundation class AudioEngine { static let sharedInstance = AudioEngine() internal var sfxPing: AVAudioPlayer private init() { self.sfxPing = AVAudioPlayer() if let path = NSBundle

Play sound with a little delay

柔情痞子 提交于 2019-12-10 19:21:31
问题 I have a sound in my app that starts automatically when appear the view; but, as the title says, I'd like that this sounds starts with a little delay, about an half second after the view appear. I tried to use PlayAtTime, but or it does not work or I have set somethings wrong... This is my code: var player = AVAudioPlayer? override func viewDidLoad() { super.viewDidLoad() playAudioWithDelay() } func playAudioWithDelay() { let file = NSBundle.mainBundle().URLForResource("PR1", withExtension:

AVAudioPlayer: volume buttons work on some devices and not others

久未见 提交于 2019-12-10 19:11:07
问题 I have an app that uses AVAudioPlayer to play some embedded MP3 files. The volume buttons work reliably on the 3GS I mostly use for testing -- they worked under 4.1 and work now after upgrading to 4.3.1. On my boss's iPhone 4 running 4.2.1, they don't seem to work in our app at at all; and on the iPod Touch (also running 4.2.1) that's my secondary test machine, I've been able to get them to work once but can't reproduce how I did it. I tried a hack I found, creating a dummy AVAudioPlayer at