Deezer SDK IOS 按 id 播放曲目
Deezer SDK IOS play track by id
official examples of Deezer's api in swift 在 DeezerManager
.
中向我们展示了一个名为 getObject
的方法
func getObject(identifier: String, callback: @escaping (_ object: Any?, _ error: Error?) -> Void) {
DZRObject.object(withIdentifier: identifier, requestManager: DZRRequestManager.default(), callback: callback)
}
我想播放 ID 为 533609232 的曲目(Drake - God's Plan)。
为此,我需要 DZRTrack
/DZRObject
。所以我打电话给:
DZRObject.object(withIdentifier: "533609232", requestManager: DZRRequestManager.default(), callback: { (data, error) in
print(data, error)
//player stuff
})
但是我有一个错误NSException
:
2019-05-02 22:50:23.845973+0200 my-app[51762:1318493] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010af7d6fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000109dd2ac5 objc_exception_throw + 48
2 CoreFoundation 0x000000010aecbddc _CFThrowFormattedException + 194
3 CoreFoundation 0x000000010af5786d -[__NSPlaceholderArray initWithObjects:count:] + 237
4 CoreFoundation 0x000000010af6c2a4 +[NSArray arrayWithObjects:count:] + 52
5 my-app 0x0000000106af3ef5 +[DZRObject infoURLWithBaseURL:identifier:] + 134
6 my-app 0x0000000106af4062 +[DZRObject objectWithRequestManager:baseURL:identifier:callback:] + 123
7 my-app 0x0000000106af3fb3 +[DZRObject objectWithIdentifier:requestManager:callback:] + 80
8 my-app 0x00000001069cd93d $s10my_app30DeezerViewControllerC5testayyF + 461
9 my-app 0x00000001069cf75e $s10my_app30DeezerViewControllerC0C6ActionyyF + 46
10 my-app 0x00000001069cf794 $s10my_app30DeezerViewControllerC0C6ActionyyFTo + 36
11 UIKitCore 0x000000010fd73204 -[UIApplication sendAction:to:from:forEvent:] + 83
12 UIKitCore 0x000000010f7c8c19 -[UIControl sendAction:to:forEvent:] + 67
13 UIKitCore 0x000000010f7c8f36 -[UIControl _sendActionsForEvents:withEvent:] + 450
14 UIKitCore 0x000000010f7c7eec -[UIControl touchesEnded:withEvent:] + 583
15 UIKitCore 0x000000010fdabeee -[UIWindow _sendTouchesForEvent:] + 2547
16 UIKitCore 0x000000010fdad5d2 -[UIWindow sendEvent:] + 4079
17 UIKitCore 0x000000010fd8bd16 -[UIApplication sendEvent:] + 356
18 UIKitCore 0x000000010fe5c293 __dispatchPreprocessedEventFromEventQueue + 3232
19 UIKitCore 0x000000010fe5ebb9 __handleEventQueueInternal + 5911
20 CoreFoundation 0x000000010aee4be1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000010aee4463 __CFRunLoopDoSources0 + 243
22 CoreFoundation 0x000000010aedeb1f __CFRunLoopRun + 1231
23 CoreFoundation 0x000000010aede302 CFRunLoopRunSpecific + 626
24 GraphicsServices 0x00000001136072fe GSEventRunModal + 65
25 UIKitCore 0x000000010fd71ba2 UIApplicationMain + 140
26 my-app 0x00000001068d4ebb main + 75
27 libdyld.dylib 0x000000010cfc9541 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
所以我不明白为什么会出现这个错误。
我做错了吗?有其他方法吗?
如 Deezer SDK 文档所述 (DZRObject.h
)
You should not call this method directly on the DZRObject class but on one
of its concrete subclass (e.g. DZRUser, DZRTrack, DZRArtist, ...)
也许试试 DZRTrack.object(withIdentifier...
?
official examples of Deezer's api in swift 在 DeezerManager
.
getObject
的方法
func getObject(identifier: String, callback: @escaping (_ object: Any?, _ error: Error?) -> Void) {
DZRObject.object(withIdentifier: identifier, requestManager: DZRRequestManager.default(), callback: callback)
}
我想播放 ID 为 533609232 的曲目(Drake - God's Plan)。
为此,我需要 DZRTrack
/DZRObject
。所以我打电话给:
DZRObject.object(withIdentifier: "533609232", requestManager: DZRRequestManager.default(), callback: { (data, error) in
print(data, error)
//player stuff
})
但是我有一个错误NSException
:
2019-05-02 22:50:23.845973+0200 my-app[51762:1318493] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010af7d6fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000109dd2ac5 objc_exception_throw + 48
2 CoreFoundation 0x000000010aecbddc _CFThrowFormattedException + 194
3 CoreFoundation 0x000000010af5786d -[__NSPlaceholderArray initWithObjects:count:] + 237
4 CoreFoundation 0x000000010af6c2a4 +[NSArray arrayWithObjects:count:] + 52
5 my-app 0x0000000106af3ef5 +[DZRObject infoURLWithBaseURL:identifier:] + 134
6 my-app 0x0000000106af4062 +[DZRObject objectWithRequestManager:baseURL:identifier:callback:] + 123
7 my-app 0x0000000106af3fb3 +[DZRObject objectWithIdentifier:requestManager:callback:] + 80
8 my-app 0x00000001069cd93d $s10my_app30DeezerViewControllerC5testayyF + 461
9 my-app 0x00000001069cf75e $s10my_app30DeezerViewControllerC0C6ActionyyF + 46
10 my-app 0x00000001069cf794 $s10my_app30DeezerViewControllerC0C6ActionyyFTo + 36
11 UIKitCore 0x000000010fd73204 -[UIApplication sendAction:to:from:forEvent:] + 83
12 UIKitCore 0x000000010f7c8c19 -[UIControl sendAction:to:forEvent:] + 67
13 UIKitCore 0x000000010f7c8f36 -[UIControl _sendActionsForEvents:withEvent:] + 450
14 UIKitCore 0x000000010f7c7eec -[UIControl touchesEnded:withEvent:] + 583
15 UIKitCore 0x000000010fdabeee -[UIWindow _sendTouchesForEvent:] + 2547
16 UIKitCore 0x000000010fdad5d2 -[UIWindow sendEvent:] + 4079
17 UIKitCore 0x000000010fd8bd16 -[UIApplication sendEvent:] + 356
18 UIKitCore 0x000000010fe5c293 __dispatchPreprocessedEventFromEventQueue + 3232
19 UIKitCore 0x000000010fe5ebb9 __handleEventQueueInternal + 5911
20 CoreFoundation 0x000000010aee4be1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000010aee4463 __CFRunLoopDoSources0 + 243
22 CoreFoundation 0x000000010aedeb1f __CFRunLoopRun + 1231
23 CoreFoundation 0x000000010aede302 CFRunLoopRunSpecific + 626
24 GraphicsServices 0x00000001136072fe GSEventRunModal + 65
25 UIKitCore 0x000000010fd71ba2 UIApplicationMain + 140
26 my-app 0x00000001068d4ebb main + 75
27 libdyld.dylib 0x000000010cfc9541 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
所以我不明白为什么会出现这个错误。 我做错了吗?有其他方法吗?
如 Deezer SDK 文档所述 (DZRObject.h
)
You should not call this method directly on the DZRObject class but on one of its concrete subclass (e.g. DZRUser, DZRTrack, DZRArtist, ...)
也许试试 DZRTrack.object(withIdentifier...
?