【问题标题】:Incompatible pointer to integer conversion passing 'SystemSoundID to parameter of type 'SystemSoundID'指向整数转换的不兼容指针将“SystemSoundID”传递给“SystemSoundID”类型的参数
【发布时间】:2014-04-08 03:33:59
【问题描述】:

我不懂 AudioToolbox 框架... 我有这行代码:

-(IBAction)PlaySound1:(id)sender{

AudioServicesPlaySystemSound(PlaySoundID1);

}

但是 xcode 给我这个错误:

指向整数转换的不兼容指针将“SystemSoundID”传递给“SystemSoundID”类型的参数

Xcode 建议我改为这样做:

-(IBAction)PlaySound1:(id)sender{

AudioServicesPlaySystemSound(*(PlaySoundID1));

}

但如果我这样做,声音就不会播放!另外,我看过很多 youtube 教程,人们甚至都没有收到错误...有没有办法在 xcode 中禁用某个警告,或者有没有办法解决这个问题?

编辑:我在代码的这一行也遇到了同样的错误:

AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL1, &PlaySoundID1);

Xcode 建议我去掉系统声音 ID 前面的“&”,但如果我这样做,声音将无法播放!唯一的声音播放是如果我与 xcode 相矛盾(我通常不会介意,但由于我有超过 100 个声音,错误的数量是荒谬的!)

【问题讨论】:

  • 显示你是如何定义PlaySoundID1的。

标签: objective-c xcode audiotoolbox


【解决方案1】:

根据您最有可能错误地定义 PlaySoundID1 的错误。

你可能有类似的东西:

SystemSoundID *PlaySoundID1;

但你需要的是:

SystemSoundID PlaySoundID1; // no asterisk

您对AudioServicesCreateSystemSoundID 的调用应该类似于:

SystemSoundID usedSoundID;
OSStatus status = AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL1, &usedSoundID);
// check the status and look at usedSoundID as needed

第二个参数是一个“out”值,所以你不应该传入你的 PlaySoundID 值。

【讨论】:

  • 我确实添加了星号...现在已修复!感谢您的宝贵时间!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-20
  • 2015-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多