iOS:这是音频会话模拟器错误吗?关键字: kAudioSessionProperty_AudioRoute kAudioSessionUnsupportedPropertyError

发布于 2024-11-18 07:32:08 字数 2409 浏览 2 评论 0原文

有人可以确认这是否确实是一个错误吗? (如果是这样,我会向苹果公司提交)。

在 4.3 之前的任何版本的模拟器上(这是撰写本文时的最新版本),尝试获取 kAudioSessionProperty_AudioRoute 都会返回错误代码 kAudioSessionUnsupportedPropertyError。

这个非常容易复制。

启动一个新项目(我使用的是 Xcode 4.0.2 Build 4A2002a,这是标准构建),基于窗口的项目“AudioSessionBug”

包括 AudioToolbox 框架,

将应用程序委托的 .m 文件替换为以下内容:

//
//  AudioSessionBugAppDelegate.m
//  AudioSessionBug
//
//  Created by Pi on 02/07/2011.
//  Copyright 2011 Pi. All rights reserved.
//

#import "AudioSessionBugAppDelegate.h"

#import <AudioToolbox/AudioToolbox.h>

#define SET_PROPERTY( prop, type, val ) \
{ \
OSStatus ret = AudioSessionSetProperty( prop, sizeof( type ), &(type){ val } ); \
if ( ret != kAudioSessionNoError ) \
{ \
NSLog( @"AudioSessionSETProperty failed for: %s!", #prop ); \
return; \
} \
}

enum  {
    kNo = 0,
    kYes = 1
};

// - - - 

@interface AudioSessionBugAppDelegate ( )

- (void) setupSession;

@end

// - - - 

@implementation AudioSessionBugAppDelegate


@synthesize window=_window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];


    [self setupSession];


    return YES;
}

- (void) setupSession
{
    OSStatus result = AudioSessionInitialize( NULL, NULL, NULL, NULL );
    assert( result == kAudioSessionNoError );

    SET_PROPERTY( kAudioSessionProperty_AudioCategory,  UInt32,   kAudioSessionCategory_PlayAndRecord );

    // make sure headphones are plugged in!
    {
        // http://stackoverflow.com/questions/2753562/what-kind-of-routes-could-i-get-back-from-kaudiosessionproperty-audioroute-proper
        CFStringRef state = nil;        
        UInt32 propertySize = sizeof(CFStringRef);
        OSStatus status = AudioSessionGetProperty( kAudioSessionProperty_AudioRoute, &propertySize, &state );

        if ( status == kAudioSessionUnsupportedPropertyError )
        {
            NSLog( @" WTF? GETTING kAudioSessionProperty_AudioRoute GIVES kAudioSessionUnsupportedPropertyError ?!?!? " );
        }

        NSLog( @" OK - done! " );

        exit( 1 );
    }
}

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

@end

检查它是否有效。

现在将部署目标更改为 4.3 之前的任何内容。说4.2。

在 iPad 模拟器 4.3 上再次运行它 -- OK
在 iPad 模拟器 4.2 上再次运行 -- 失败

can someone confirm whether this is indeed a bug? ( If so I will go off and file it with Apple ).

attempting to fetch kAudioSessionProperty_AudioRoute is returning error code kAudioSessionUnsupportedPropertyError on any version of the simulator prior to 4.3 ( which is the latest version at time of writing ).

this one is dead easy to reproduce.

Start a new project ( I am using Xcode 4.0.2 Build 4A2002a, that is the standard build ), window-based project "AudioSessionBug"

include AudioToolbox framework

replace the application delegate's .m file with the following:

//
//  AudioSessionBugAppDelegate.m
//  AudioSessionBug
//
//  Created by Pi on 02/07/2011.
//  Copyright 2011 Pi. All rights reserved.
//

#import "AudioSessionBugAppDelegate.h"

#import <AudioToolbox/AudioToolbox.h>

#define SET_PROPERTY( prop, type, val ) \
{ \
OSStatus ret = AudioSessionSetProperty( prop, sizeof( type ), &(type){ val } ); \
if ( ret != kAudioSessionNoError ) \
{ \
NSLog( @"AudioSessionSETProperty failed for: %s!", #prop ); \
return; \
} \
}

enum  {
    kNo = 0,
    kYes = 1
};

// - - - 

@interface AudioSessionBugAppDelegate ( )

- (void) setupSession;

@end

// - - - 

@implementation AudioSessionBugAppDelegate


@synthesize window=_window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];


    [self setupSession];


    return YES;
}

- (void) setupSession
{
    OSStatus result = AudioSessionInitialize( NULL, NULL, NULL, NULL );
    assert( result == kAudioSessionNoError );

    SET_PROPERTY( kAudioSessionProperty_AudioCategory,  UInt32,   kAudioSessionCategory_PlayAndRecord );

    // make sure headphones are plugged in!
    {
        // http://stackoverflow.com/questions/2753562/what-kind-of-routes-could-i-get-back-from-kaudiosessionproperty-audioroute-proper
        CFStringRef state = nil;        
        UInt32 propertySize = sizeof(CFStringRef);
        OSStatus status = AudioSessionGetProperty( kAudioSessionProperty_AudioRoute, &propertySize, &state );

        if ( status == kAudioSessionUnsupportedPropertyError )
        {
            NSLog( @" WTF? GETTING kAudioSessionProperty_AudioRoute GIVES kAudioSessionUnsupportedPropertyError ?!?!? " );
        }

        NSLog( @" OK - done! " );

        exit( 1 );
    }
}

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

@end

check that it works.

now change deployment target to anything prior to 4.3. say 4.2.

run it again on iPad simulator 4.3 -- OK
run it again on iPad simulator 4.2 -- FAIL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

北渚 2024-11-25 07:32:08

我刚刚收到 Apple 的以下确认信息:

这是 4.3 中修复的错误,我们目前没有计划修复模拟器早期版本中的错误。

I just received the following confirmation from Apple:

This was a bug that was fixed in 4.3 and we currently have no plans to fix bugs in earlier builds of the simulator.

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