avaudioplayer

Can I play a sound with vibrate using AVAudioPlayer?

别来无恙 提交于 2019-12-10 10:38:46
问题 I have AVAudioPlayer playing a sound for a message alert during chat, I also want the phone to vibrate. Is it possible to do this in AVAudioPlayer or do I need to use a different method? Thanks 回答1: To play a sound: NSString *source = [[NSBundle mainBundle] pathForResource:@"beep" ofType:@"mp3"]; self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:source] error:nil]; self.audioPlayer.delegate = self; self.audioPlayer.numberOfLoops = 0; self.audioPlayer

Audio - Jump Forward 30 Seconds

我只是一个虾纸丫 提交于 2019-12-10 10:38:35
问题 I've got an audio player that plays audio retrieved from Core Date. Play & pause work fine. I'm trying to implement a 'Jump Forward 30 Seconds' button and seeking any pointers as to how I would go about that. Code for my 'Play/pause' button @IBAction func playPressed(sender: AnyObject) { let play = UIImage(named: "play") let pause = UIImage(named: "pause") if audioPlayer.playing { pauseAudioPlayer() audioPlayer.playing ? "\(playButton.setImage( pause, forState: UIControlState.Normal))" : "\

iPhone SDK: Play a single WAV from a button

对着背影说爱祢 提交于 2019-12-10 10:38:19
问题 I am currently trying out this code: NSString *path = [[NSBundle mainBundle] pathForResource:@"dream" ofType:@"m4a"]; AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; theAudio.delegate = self; [theAudio play]; However, the SDK says that the ViewController does not implement the AVAudioPlayer Delegate. Any body any ideas on how to play a WAV (or M4a) using the 2.2 SDK? 回答1: You need to add <AVAudioPlayerDelegate> to the end of your

AVAudioPlayer returns success but no sound from device

血红的双手。 提交于 2019-12-10 09:52:36
问题 I have a very simple app that I have built to test out AVAudioPlayer. I have a 16s aif file that plays just fine on my Mac. Put it in a simple app and ran on my iPhone but no sound. Sending 'play' to the object returns success and audioPlayerDidFinishPlaying comes back with success after 16 seconds. Still no sound. Have checked the sound volume on the iPhone, just fine. Have checked to make sure my AVAudioPlayer object has volume set at 1.0 - it does. Can anybody help? Here's my code NSString

AVAudioPlayer and AVAudioRecorder: Delegate Methods not Called

不想你离开。 提交于 2019-12-10 09:34:21
问题 My delegate methods audioRecorderDidFinishRecording and audioPlayerDidFinishPlaying are not being called. Those methods should trigger a 'stopanimation` method that stops an animation after recording is finished. I have placed a call call to the stopanimation method at the end of audioPlayerDidFinishPlaying . Here is the relevant code where the delegate is assigned: VoiceEditor.h @interface VoiceEditor : UIViewController <UITextFieldDelegate, AVAudioRecorderDelegate, AVAudioPlayerDelegate>{ }

AVAudioPlayer Error using iOS Simulator

若如初见. 提交于 2019-12-10 06:38:22
问题 following problem: <0xb03e7000> Error '!obj' trying to fetch default input device's sample rate <0xb03e7000> Error getting audio input device sample rate: '!obj' <0xb03e7000> AQMEIOManager::FindIOUnit: error '!dev' I found this problem already here on stackoverflow but none of the provided solutions worked for me. Code: #import "CJTActionViewController.h" @interface CJTActionViewController() @property NSURL *url; @property NSData *songFile; @property AVAudioPlayer *audioPlayer; @end

iOS开发音频播放基础——AVAudioPlayer的应用

♀尐吖头ヾ 提交于 2019-12-10 06:08:09
iOS音频开发——AVAudioPlayer应用 AVAudioPlayer是系统提供给我们的一个音频播放类,在AVFoundation框架下,通过它,我们可以实现一个功能强大的音乐播放器。首先,在项目中我们需要导入AVFoundation这个框架。 一、AVAudioPlayer方法与属性详解 初始化方法有两种,通过音频的路径或者音频data数据初始化player对象 - (instancetype)initWithContentsOfURL:(NSURL *)url error:(NSError **)outError; - (instancetype)initWithData:(NSData *)data error:(NSError **)outError; 注意:支持的音频格式有:AAC,ALAC,HE-AAC,iLBC,IMA4,MP3. 准备播放音频,返回值标志是否解析成功,是否可以播放。 - (BOOL)prepareToPlay; 开始播放音频 - (BOOL)play; 在一段时间间隔后播放 - (BOOL)playAtTime:(NSTimeInterval)time; 暂停播放,并且准备好继续播放 - (void)pause; 停止播放,不再准备好继续播放 - (void)stop; 获取是否正在播放 @property(readonly, getter

IOS开发之AVAudioPlayer的基本使用

a 夏天 提交于 2019-12-10 05:57:16
1.这是播放效果,可以按下play和pause播放和暂停,进度条自动改变进度 ,我用的是mac mini产生很多错误,没有声音,换个耳机就可以了!! 滑动条拖动的时候,音乐播放改变会有噪音,解决方法如下 不要勾这个就行 2.改变声音的方法,设置当前音量和最小音量0-1的数值 以下实现音乐播放的代码: // // ViewController.m // 01-AVAudiioPlayer // // Created by 鹿微微鹿 . on 16/5/6. // Copyright (c) 2016 年 鹿微微鹿 . All rights reserved. // //AVAudioPlayer: 专门用来播放音频的工具 //1. 导入 import <AVFoundation/AVFoundation.h> //2. 声明一个音频全局变量 AVAudioPlayer *_player #import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface ViewController ()< AVAudioPlayerDelegate > { // 声明一个音频播放器对象 AVAudioPlayer *_player; } @property ( weak , nonatomic ) IBOutlet

AVAudioPlayer音频播放器—IOS开发

女生的网名这么多〃 提交于 2019-12-10 05:56:49
IOS中有三种播放音频的方式:AVAudioPlayer、音频服务、音频队列。 本文只讲解AVAudioPlayer。 AVAudioPlayer在AVFoundation框架下,所以我们要导入AVFoundation.framework。 一、创建一个播放器 NSError* err; _avAudioPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource: @"RHAPSODY IN BLUE" ofType:@"mp3" inDirectory:@"/"]] error:err ];//使用本地URL创建 或 AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithData:myData error:&err ];//使用NSData创建 AVAudioPlayer不可以播放网络URL,但是可以播放NSData,我们似乎受到了点启发,我们可以通过网络URL去创建NSData,然后在通过AVAudioPlayer来播放NSData,这样是不是就可以播放网络音乐了呢?但是此法并不可取,因为AVAudioPlayer只能播放一个完整的文件,并不支持流式播放

AVAudioPlayer 音频播放器 使用 教程

我的梦境 提交于 2019-12-10 05:47:15
IOS中有三种播放音频的方式:AVAudioPlayer、音频服务、音频队列。 此文主要讲AVAudioPlayer,其他两个请见相关文章。 AVAudioPlayer 在AVFoundation框架下,所以我们要导入AVFoundation.framework。 AVAudioPlayer 类封装了播放单个声音的能力。播放器可以用NSURL或者NSData来初始化,要注意的是NSURL并不可以是网络url而必须是本地文件URL,因为 AVAudioPlayer不具备播放网络音频的能力,不过我们可以用过一点小手段使其具备这个能力,留待稍后讲解。 一个AVAudioPlayer只能播放一个音频,如果你想混音你可以创建多个AVAudioPlayer实例,每个相当于混音板上的一个轨道。 一、创建一个播放器 源码 打印 ? # import <AVFoundation/AVFoundation.h> NSError* err; AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: [[NSBundle mainBundle]pathForResource: @ "music" ofType:@ "m4a" inDirectory:@ "/" ]] error: