如何为当前播放的歌曲实现音量计? (iPhone操作系统3.1.3)

发布于 2024-09-03 10:21:08 字数 752 浏览 3 评论 0原文

我对核心音频非常陌生,我只是需要一些帮助来为通过耳机或内置扬声器输出的任何内容(例如分贝计)编写一个小音量表。我有以下代码,并且一直在尝试完成苹果源项目“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉服软 2024-09-10 10:21:08

您可以使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文