如何为当前播放的歌曲实现音量计? (iPhone操作系统3.1.3)
我对核心音频非常陌生,我只是需要一些帮助来为通过耳机或内置扬声器输出的任何内容(例如分贝计)编写一个小音量表。我有以下代码,并且一直在尝试完成苹果源项目“SpeakHere”,但是在不知道它是如何工作的情况下尝试完成所有这些是一场噩梦......有人可以阐明一些吗?
这是我到目前为止的代码......
(void)displayWaveForm
{
while (musicIsPlaying == YES {
NSLog(@"%f",sizeof(AudioQueueLevelMeterState));
}
}
(IBAction)playMusic
{
if (musicIsPlaying == NO) {
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/track7.wav",[[NSBundle mainBundle] resourcePath]]];
NSError *error;
music = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
music.numberOfLoops = -1;
music.volume = 0.5;
[music play];
musicIsPlaying = YES;
[self displayWaveForm];
}
else {
[music pause];
musicIsPlaying = NO;
}
}
I'm very new to core audio and I just would like some help in coding up a little volume meter for whatever's being outputted through headphones or built-in speaker, like a dB meter. I have the following code, and have been trying to go through the apple source project "SpeakHere", but it's a nightmare trying to go through all that, without knowing how it works first... Could anyone shed some light?
Here's the code I have so far...
(void)displayWaveForm
{
while (musicIsPlaying == YES {
NSLog(@"%f",sizeof(AudioQueueLevelMeterState));
}
}
(IBAction)playMusic
{
if (musicIsPlaying == NO) {
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/track7.wav",[[NSBundle mainBundle] resourcePath]]];
NSError *error;
music = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
music.numberOfLoops = -1;
music.volume = 0.5;
[music play];
musicIsPlaying = YES;
[self displayWaveForm];
}
else {
[music pause];
musicIsPlaying = NO;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 AVAudioPlayer 类进行计量,首先 启用它然后获取平均功率用作仪表数据 avTouch 有一个 工作示例
you can use metering with the AVAudioPlayer class, first enable it then get the average power to use as your meter data avTouch has a working example