iphone - 系统音频播放使运行iOS 4.2.1的iPhone保持静音

标签 iphone cocoa-touch audio ios4

问题

我正在尝试在iOS应用中播放一小段(4秒)音频剪辑。

  • 在设备(带有iOS 4.2.1的iPhone 3G)上,我保持沉默。但是,振动确实会根据需要触发。
  • 在模拟器中,音频按预期播放。

  • 我正在Snow Leopard 10.6.8之上的VMWare上的Lion VM实例10.7.2中运行。

    我尝试过的
  • 检查格式-它是线性PCM文件
  • 将文件转换为16位音频文件(Audacity认为它是32位)
  • 确保代码和文件的文件名大小写相同。
  • 清理了目标,将其从iPhone中删除并重建。

  • 代码
        // Usage from class
        -(void)loadRunningView {
            JGTimerRunningViewController *runningViewController = [[JGTimerRunningViewController alloc] initWithNibName:@"JGRunningViewController" bundle:nil];
            [runningViewController loadAlertSoundWithFilename:@"DigitalAlarm1"];
        }
    
        @interface JGTimerRunningViewController : UIViewController {
            IBOutlet UILabel *timeLabel;
            CFURLRef soundFileURLRef;
            SystemSoundID soundFileObject;
        }
    
        @implementation JGTimerRunningViewController
    
        -(void)loadAlertSoundWithFilename:(NSString *)alertSoundFilename_ {
            // Get the main bundle for the app
            CFBundleRef mainBundle = CFBundleGetMainBundle ();
            CFStringRef filename = (CFStringRef)alertSoundFilename_;
            soundFileURLRef = CFBundleCopyResourceURL (mainBundle, filename, CFSTR ("aiff"), NULL);
            // Create a system sound object representing the sound file
            AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);
        }
        ..
        -(IBAction)playSound:(id)sender {
            AudioServicesPlaySystemSound (soundFileObject);
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
        }
    
        -(void)showRedCard {
            [[self view] setBackgroundColor:[UIColor redColor]];
            [self playSound:self];
        }
        ...
        - (void)dealloc {
            CFRelease(soundFileURLRef);
            AudioServicesDisposeSystemSoundID(soundFileObject);
            [timeLabel release];
            [super dealloc];
        }
        @end
    

    最佳答案

    您是否检查过文件大小写与文件名匹配的大小写,即“DigitalAlarm1”而不是“Digitalalarm1”,等等。模拟器不区分大小写,但设备区分大小写。

    关于iphone - 系统音频播放使运行iOS 4.2.1的iPhone保持静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8790260/

    相关文章:

    ios - 裁剪音频文件

    ios - MPNowPlayingInfoCenter 在通过播放音频时始终处于 "playing"状态

    iphone - NSDateComponents 因 2 个日期的差异而缺少 1 秒

    iphone - 如何在 UILabel 的背景框架上设置阴影?

    iphone - 自定义表格 View 背景的 UITableViewCell 颜色问题

    iphone - 开发 iPod 需要哪些软件和硬件?在电脑上?

    ios - 如何禁用特定文本字段上的键盘但允许选择器 View 作为输入 Swift?

    iphone - 寻找有关将 GPS 与我自己创建的 map 一起使用的通用指南 - iOS

    ios - 自动续订订阅收据验证

    android - 使用Android MediaPlayer流式传输ac3时无音频