【问题标题】:Create SystemSoundID failed iOS - OSStatus = 0 [closed]创建 SystemSoundID 失败 iOS - OSStatus = 0 [关闭]
【发布时间】:2012-12-27 01:27:47
【问题描述】:

我在这里遇到了一个非常相似的问题:link 在 ViewController.h 文件中我添加了这个:

#import <UIKit/UIKit.h>
#include <AudioToolbox/AudioToolbox.h>

@interface ViewController : UIViewController
@property SystemSoundID outSystemSoundID1;
@end

在 ViewController.m 中:

#import <ViewController.h>
@interface ViewController ()
- (IBAction)playtrack;


@end

@implementation ViewController

@synthesize outSystemSoundID1;

- (void)viewDidLoad
{
[super viewDidLoad];

NSString *path1 = [[NSBundle mainBundle] pathForResource:@"1000Hz-0-4sec" ofType:@"wav"];
NSURL *url1 = [NSURL fileURLWithPath:path1];
//CFURLRef lol = (CFURLRef)objc_unretainedPointer(url1);
//AudioServicesCreateSystemSoundID( lol, &outSystemSoundID1);
OSStatus status = AudioServicesCreateSystemSoundID((__bridge CFURLRef)url1, &outSystemSoundID1);
NSLog(@"AudioServicesCreateSystemSoundID status = %ld", status);
}

- (IBAction)playtrack {
AudioServicesPlaySystemSound (outSystemSoundID1);
}
@end

我要播放的声音文件在 Supporting Files 下。

OSStatus 说:

AudioServicesCreateSystemSoundID 状态 = 0

我为 CFURLRef 尝试了很多不同的组合,就像您在注释掉的部分中看到的那样。

也许我的文件不被支持?在我得到解决方案后,我想用这种方式初始化 3 个 aif 格式的声音文件。

希望你能帮助我!谢谢:)

我已激活 ARC,并且使用的是 iOS 6.0.1 (iPhone)

【问题讨论】:

    标签: ios audiotoolbox system-sounds


    【解决方案1】:

    OSStatus = 0 表示“没有错误”,这意味着函数AudioServicesCreateSystemSoundID 确实成功

    【讨论】:

    • 但是为什么当我按下按钮时应用程序总是崩溃(连接到 - (IBAction)playtrack )?我需要在这个方法中添加“(id)sender”吗?
    • @mrlowalowa:当应用程序崩溃时,您是否收到任何错误消息?
    • 我在 main 中找到了一些指向自动释放的地方但是我在这个 ViewControll.C 文件中也运行了一个不同的 IBAction。在我将它与另一个按钮放在一起后,我听到了声音......我创建了 3 个其他工作正常的方法,但它们不受不同按钮左右的影响。如果我有 2 个不同的 IBActions,它可能会超载..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 2017-10-29
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多