avaudioplayer

How to customize MPVolumeView?

这一生的挚爱 提交于 2019-12-02 16:21:10
I have tried many methods to implement a regular UISlider and control the device volume, but it's all Native-C functions which results in many untraceable bugs. I tried the MPVolumeView it works like charm, it even controls the device volume even after you close the app, just like the iPod app. My question is, is there anyway to customize the MPVolumeView with specific colors and images, just like UISlider ? NOTE: I want a legal method without using private undocumented APIs. UPDATE As per @Alexsander Akers answer, since the sub views are hidden in MPVolumeView I had to cycle through subviews,

How to play sound from tcp stream in java

被刻印的时光 ゝ 提交于 2019-12-02 13:09:04
问题 There is another app that writes raw wav file on this socket. The client starts and begins listening to the song which is currently playing. Socket clientSocket = new Socket("localhost", 9595); AudioInputStream stream = AudioSystem.getAudioInputStream(clientSocket.getInputStream()); I get javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream Doc about AudioSystem.getAudioInputStream: "Obtains an audio input stream from the provided input stream.

AVAudioPlayer Play audio on music plays on the sound box of phone calls

怎甘沉沦 提交于 2019-12-02 12:53:40
I have a simple code using AVAudioPlayer, to play a .caf audio: AppDelegate.h AVAudioPlayer *_audioPlayer; AppDelegate.m - (void)playAudio{ NSArray *dirPaths; NSString *docsDir; dirPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); docsDir = dirPaths[0]; NSString *soundFilePath = [docsDir stringByAppendingPathComponent:audiosrc]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil]; _audioPlayer.volume = 1.0; [_audioPlayer play]; } The audio play very well, but he

How do I fastforward using AVAudioplayer while hearing the music?

孤者浪人 提交于 2019-12-02 12:20:22
I got it to fast forward but I would like to hear the music when its fast forwarding. How would I be able to do this? Here is the code I have: if node.name == "left" { var time = musicPlayer.currentTime time += 1.0 musicPlayer.enableRate = true musicPlayer.rate = 2.0 if time > musicPlayer.duration { } else { musicPlayer.currentTime = time } } Have a look at the rate property on AVAudioPlayer This property’s default value of 1.0 provides normal playback rate. The available range is from 0.5 for half-speed playback through 2.0 for double-speed playback. To set an audio player’s playback rate,

AVAudioPlayer not playing m4a or mp3 filetype from a website

Deadly 提交于 2019-12-02 11:22:43
I am trying to locate a URL which is only pure .m4a sound with my application. I have the URL to the audio and theoretically download it. Then, with the downloaded fileURL to the sound, I try to play it with the AVAudioPlayer, yet it does not play any sound. Here is my code: In the URL retrieval function, I call: (urls defined as a URL(string: url) , url being the retrieve URL string) downloadSound(url: urls!) Here is my downloadSound() function: func downloadSound(url:URL){ var downloadTask:URLSessionDownloadTask downloadTask = URLSession.shared.downloadTask(with: url, completionHandler: {

Make AVAudioPlayer play a music file through phone call (ear) speaker

[亡魂溺海] 提交于 2019-12-02 11:02:04
I want to play a music file through ear speaker, What I am doing now is: In viewDidLoad method :::: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [[AVAudioSession sharedInstance] setActive: YES error: nil]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; Initializing music file in viewDidLoad :::: musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"1985_Ring_" ofType:@"wav"]]; click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil]; Now Playing file after routing audio in a method ::::: [

Can't play file from documents in AVAudioPlayer

霸气de小男生 提交于 2019-12-02 07:59:00
问题 I have a file on documents folder of app and I want to play it. if NSFileManager.defaultManager().fileExistsAtPath(pathString) { let url = NSURL(fileURLWithPath:pathString, isDirectory: false) do { let player = try AVAudioPlayer(contentsOfURL:url) player.prepareToPlay() player.play() } catch let error as NSException { print(error) } catch {} } There is a file on file system and I checked its existence. Also all lines in do block are executed. There is neither exception nor error and still no

How to multiple play() in audioPlayerDidFinishPlaying method

余生长醉 提交于 2019-12-02 06:42:37
问题 When I press "yourButton" or "yourButton2" or "yourButton3" each plays an audio file and while the audio is playing the UIButton is set selected. I would like "yourButton4" to implement the method of the other UIButtons in a row. (At first, plays an audio file and set selected "yourButton" then "yourButton2" and "yourButton3") . However, when I press "yourButton4", "yourButton2" and "yourButton3" is played at same time as play() method Plays a sound asynchronously. let url1 = Bundle.main

how can i play remote .mp3 file in my ios application?

落爺英雄遲暮 提交于 2019-12-02 05:20:32
问题 I'm trying to play remote .mp3 file but its giving the following error. The operation couldn’t be completed. (OSStatus error -43.) here is my code : - (void)viewDidLoad { [super viewDidLoad]; isPlaying = NO; /* NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Dar-e-Nabi-Per" ofType:@"mp3"]]; */ NSURL *url = [NSURL URLWithString:@"http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3"]; NSError *error; audioPlayer = [[AVAudioPlayer alloc]

Swift: Keep playing sounds when the device is locked

為{幸葍}努か 提交于 2019-12-02 05:16:52
I'm using the following code to play a sound off a URL from the internet: var audioPlayer = AVPlayer() ... let audioSession = AVAudioSession.sharedInstance() audioSession.setCategory(AVAudioSessionCategoryAmbient, error: nil) let url = trackFileName let playerItem = AVPlayerItem( URL:NSURL( string:url ) ) audioPlayer = AVPlayer(playerItem:playerItem) audioPlayer.rate = 1.0; player.play() I'm trying to make sure it keeps playing in the background which is the reason why I'm using "AVAudioSession.sharedInstance()". When I try it out in the simulator by locking the screen, it keeps playing like