【问题标题】:Playing Audio file depending on position of image which is moving using Accelerometer根据使用加速度计移动的图像的位置播放音频文件
【发布时间】:2010-12-12 22:26:20
【问题描述】:

我正在尝试制作一个汽车在路上行驶的项目

如果我的车在路上越过车道,我想发出警告信号 如果汽车在其他车道上,如何知道汽车的位置并播放音频。

这对我来说有点紧迫

谢谢

【问题讨论】:

  • 这个应用程序应该检测真车的位置吗?
  • 你不知道自己对象的位置吗?如果是这样,那么我认为问题在于知道如何播放声音。
  • 请告诉我们您的尝试。这里不是要求为您编写应用程序的地方。

标签: iphone iphone-sdk-3.0


【解决方案1】:

您可以使用此代码播放声音:

-(void)playSomeSound
{
    NSURL *soundFilePath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"]];
    AVAudioPlayer *sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFilePath error:nil];
    [sound play];
    [sound release];
}

只要您的车越过车道,只需调用 [self playSomeSound]。其他格式的声音也可以,但不是全部都可以,所以要小心。

【讨论】:

    猜你喜欢
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多