作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 POVoiceHUD 应用程序中的控件来录制语音。
https://github.com/polatolu/POVoiceHUD
我似乎遗漏了一些让文件播放/检索录制的音频的东西。演示项目不包括存储在 [self.voiceHud startForFilePath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];
中的录制项目的播放
我尝试过使用:
- (IBAction)play:(id)sender {
NSLog(@"playRecording");
// Init audio with playback capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recordTest.caf", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
_voiceHud = [[POVoiceHUD alloc] initWithContentsOfURL:url error:&error];
[_voiceHud play];
}
但是我收到错误不兼容的指针类型
和没有已知的类选择器
最佳答案
这里 POVoiceHUD 文件负责录制您的音频文件。为了播放这个录制的文件,您需要在 viewVontroller.h 和 .m 以及 POVoiceHUD.h 和 .m 中添加一些代码
试试这段代码
在 POVoiceHUD.h 中包含此行
AVAudioPlayer *player;
- (void)playRecording:(NSURL*)_url;
POVoiceHUD.m
- (void)playRecording:(NSURL*)_url {
[self cancelRecording];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
NSError *error;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:_url error:&error];
[player prepareToPlay];
[player play];
}
内部 View Vontroller.h
- (IBAction)btnRecordTapped:(id)sender;
- (IBAction)btnPlayTapped:(id)sender;
ViewController.m
- (IBAction)btnRecordTapped:(id)sender {
[self.voiceHud startForFilePath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];
}
- (IBAction)btnPlayTapped:(id)sender
{
[self.voiceHud cancelRecording];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];
[self.voiceHud playRecording:url];
}
希望对你有帮助。
关于ios - 如何从 POVoiceHUD 播放录制的音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16833416/
我正在使用 POVoiceHUD 应用程序中的控件来录制语音。 https://github.com/polatolu/POVoiceHUD 我似乎遗漏了一些让文件播放/检索录制的音频的东西。演示项目
我是一名优秀的程序员,十分优秀!