这是我们所做的:
我们将框架添加到我们的项目中
在我们的课程之一中具有以下内容:
GCSearchViewController.h
@interface GCSearchViewController : UIViewController<UISearchBarDelegate, GNSearchResultReady, GNAudioSourceDelegate>
GCSearchViewController.m
// - As per the web tutorial
#import <GracenoteMusicID/GNConfig.h>
#import <GracenoteMusicID/GNOperations.h>
#import <GracenoteMusicID/GNSearchResponse.h>
#import <GracenoteMusicID/GNSearchResult.h>
// - As per what we saw in the demo app
#import <GracenoteMusicID/GNRecognizeStream.h>
#import <GracenoteMusicID/GNAudioConfig.h>
#import <GracenoteMusicID/GNAudioSourceMic.h>
#import <AVFoundation/AVAudioSession.h>
…
#pragma mark - Gracenote Delegate
-(void) identifySong {
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL response){
NSLog(@"Allow microphone use response: %d", response);
if (response) {
[GNOperations recognizeMIDStreamFromMic:self config:self.config];
}
}];
}
- (void) GNResultReady:(GNSearchResult *) result
{
GNSearchResponse *best = [result bestResponse];
if (![result isFailure] && (best.artist!=nil)) {
NSLog(@"Artist %@", best.artist);
NSLog(@"Song name %@", best.trackTitle);
} else {
NSLog(@"No Match");
}
}
- (void) audioBufferDidBecomeReady:(GNAudioSource*)audioSource samples:(NSData*)samples {
NSError *err;
err = [self.recognizeFromPCM writeBytes:samples];
if (err) {
NSLog(@"ERROR: %@",[err localizedDescription]);
}
}
此代码在模拟器中运行正常,但每当我们在设备(ipod touch 5th 或 iphone 5)上运行它时,应用程序就会因以下错误而中断:
2013-11-16 22:00:40.402 GC[1758:60b] 22:00:40.401 ERROR: [0x3c29f18c] >aurioc> 783: failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, non-inter> inf< 1 ch, 44100 Hz, Int16>)
Error: 0xffffd59d2013-11-16 22:00:52.904 Leaf[1758:60b] Allow microphone use response: 1
2013-11-16 22:00:52.925 GC[1758:60b] 22:00:52.925 ERROR: [0x3c29f18c] >aurioc> 783: failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, non-inter> inf< 1 ch, 44100 Hz, Int16>)
Error: 0xffffd59d2013-11-16 22:00:52.927 GC[1758:60b] *** Assertion failure in -[GNFingerprinterQueue startupTimerFired], /home/mobile/z-15003-ecma-3.2/cddb-clients/mmid/iOSMobileSDK/3.2/Classes/Private/GNFingerprinterQueue.m:291
2013-11-16 22:00:52.930 GC[1758:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'audioSource is nil'
*** First throw call stack:
(0x2fb66f4b 0x39e7b6af 0x2fb66e25 0x3050efe3 0x151849 0x1520e5 0x3054ae9b 0x2fb32183 0x2fb31653 0x2fb2fe47 0x2fa9ac27 0x2fa9aa0b 0x3478a283 0x3233e049 0x7b621 0x3a383ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
我们的应用程序针对的是 iOS7 ......感谢任何关于如何使其工作的指针