Posts

Post not yet marked as solved
0 Replies
355 Views
Hi, In iOS 17.0 Apple introduced a favorite button for the music app. This favorite button is available everywhere including Control Center and CarPlay. My question is if there is a way to show/use this favorite button in my own app. Couldn't find it in the documentation. Thank you..!
Posted
by wotson.
Last updated
.
Post not yet marked as solved
1 Replies
324 Views
Hi there, It seems I'm getting crashes in the Apple Music subscription view sometimes. Couldn't figure out why. crash_info_entry_0 _MusicKit_SwiftUI/MusicSubscriptionOffer.swift:73: Fatal error: Unexpectedly changed musicSubscriptionOffer's isPresented binding to true while internal presentation state is loading(MusicSubscriptionOffer.Options(messageIdentifier: .join, itemID: 331661274, affiliateToken: ....)). It's important to note I am displaying it from UIKit ObjC and so I had to go through some hoops in order to get this to working. Here's the relevant code: // // MusicSubscriptionOfferView.swift // import Foundation import MusicKit import Combine import SwiftUI struct MusicSubscriptionOfferView: View { @StateObject var viewModel = MusicSubscriptionOfferViewModel() var body: some View { EmptyView() .musicSubscriptionOffer( isPresented: $viewModel.isShowingOffer, options: viewModel.offerOptions ) } } class MusicSubscriptionOfferViewModel: NSObject, ObservableObject { @Published var isShowingOffer = false static var musicItemID: MusicItemID? var canBecomeSubscriber = false var offerOptions: MusicSubscriptionOffer.Options { get { var options = MusicSubscriptionOffer.Options() options.affiliateToken = "..." options.itemID = MusicSubscriptionOfferViewModel.musicItemID return options } } var subscriptions = Set<AnyCancellable>() override init() { super.init() Task { for await subscription in MusicSubscription.subscriptionUpdates { MyApp.sharedInstance().canBecomeSubscriber = subscription.canBecomeSubscriber } } NotificationCenter.default .publisher(for: NSNotification.Name(K_SHOW_APPLE_MUSIC_SUBSCRIPTION)) .sink { [weak self] _ in self!.isShowingOffer = true } .store(in: &subscriptions) } } MusicSubscriptionOfferViewModel is initiated on launch, so MyApp.sharedInstance().canBecomeSubscriber receives a value upon launch. and: @objcMembers final class MusicOfferProxyViewController: UIHostingController<MusicSubscriptionOfferView> { required init() { super.init(rootView: MusicSubscriptionOfferView()) } @objc required dynamic init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } From the UIKit view controller: MusicKitInterop* musicKitObject = [[MusicKitInterop alloc] init]; [self.view addSubview:musicKitObject.musicOfferProxyViewController.view]; [self addChildViewController:musicKitObject.musicOfferProxyViewController]; self.musicKitInterop = musicKitObject; class MusicKitInterop: NSObject { var musicOfferVC: MusicOfferProxyViewController override init() { musicOfferVC = MusicOfferProxyViewController() } @objc func musicOfferProxyViewController() -> UIViewController { return musicOfferVC } @objc func canBecomeSubscriber() -> Bool { return MyApp.sharedInstance().canBecomeSubscriber } }
Posted
by wotson.
Last updated
.
Post not yet marked as solved
0 Replies
714 Views
Hi, It seems canBecomeSubscriber of MusicSubscription returns false even if the user is eligible for a subsciption, unless the user has authorized to access his music library. Is that correct? It's kind of a shame, but I guess there's some logic to it.
Posted
by wotson.
Last updated
.
Post not yet marked as solved
2 Replies
569 Views
Hi, I am using ShazamKit to detect songs from a live stream. I am using matchStreamingBuffer with a PCMBuffer. It looks like it works for the most part, but sometimes it throws an NSException. Here's the code calling the match: engine.mainMixerNode.installTap(onBus: 0, bufferSize: 4096, format: options.audioFormat) { buffer, time in do { self.session.matchStreamingBuffer(buffer, at: time) } catch { } } The exception: Supplied audio format is not supported <CMAudioFormatDescription 0x2828a29e0 [0x20f7863a0]> { mediaType:'soun' mediaSubType:'lpcm' mediaSpecific: { ASBD: { mSampleRate: 44100.000000 mFormatID: 'lpcm' mFormatFlags: 0x29 mBytesPerPacket: 4 mFramesPerPacket: 1 mBytesPerFrame: 4 mChannelsPerFrame: 2 mBitsPerChannel: 32 } cookie: {(null)} ACL: {Stereo (L R)} FormatList Array: { Index: 0 ChannelLayoutTag: 0x650002 ASBD: { mSampleRate: 44100.000000 mFormatID: 'lpcm' mFormatFlags: 0x29 mBytesPerPacket: 4 mFramesPerPacket: 1 mBytesPerFrame: 4 mChannelsPerFrame: 2 mBitsPerChannel: 32 }} } extensions: {(null)} } This is the stack stack: 0 CoreFoundation 0xa248 __exceptionPreprocess 1 libobjc.A.dylib 0x17a68 objc_exception_throw 2 ShazamKit 0x159d0 -[SHMutableSignature appendBuffer:atTime:error:] 3 ShazamKit 0x6d7c -[SHSignatureGenerator appendBuffer:atTime:error:] 4 ShazamKit 0x3968 -[SHSessionDriverSignatureSlot appendBuffer:atTime:error:] 5 ShazamKit 0x10430 -[SHSignatureBuffer flow:time:] 6 ShazamKit 0x2490 -[SHStreamingSessionDriver flow:time:] 7 ShazamKit 0xf784 -[SHSession matchStreamingBuffer:atTime:] 8 MyApp 0x17f69c thunk for @escaping @callee_guaranteed (@guaranteed AVAudioPCMBuffer, @guaranteed AVAudioTime) -> () (<compiler-generated>) 9 AVFAudio 0x482ac AVAudioNodeTap::TapMessage::RealtimeMessenger_Perform() 10 AVFAudio 0x71c4 CADeprecated::RealtimeMessenger::_PerformPendingMessages() 11 AVFAudio 0x471e4 invocation function for block in CADeprecated::RealtimeMessenger::RealtimeMessenger(applesauce::dispatch::v1::queue) I don't mind failing if the format is not good, but how can I avoid crashing?
Posted
by wotson.
Last updated
.
Post not yet marked as solved
3 Replies
1.3k Views
Hi, I'm trying to convert a stream into a PCMBuffer and then use Shazam to match. Shazam always fails to match. I have a theory it "listens" to the playback at double speed or more. Starts from here: ... let format = audioEngine.outputNode.inputFormat(forBus: 0) guard let pcmBuffer = format.toPCMBuffer(frame: currentFrame) else {          return } session.matchStreamingBuffer(pcmBuffer, at: nil) Where toPCMBuffer is: extension AVAudioFormat {     func toPCMBuffer(frame: AudioFrame) -> AVAudioPCMBuffer? {         guard let pcmBuffer = AVAudioPCMBuffer(pcmFormat: self, frameCapacity: UInt32(frame.dataWrap.size[0]) / streamDescription.pointee.mBytesPerFrame) else {             return nil         }         pcmBuffer.frameLength = pcmBuffer.frameCapacity         for i in 0 ..< min(Int(pcmBuffer.format.channelCount), frame.dataWrap.size.count) {             frame.dataWrap.data[i]?.withMemoryRebound(to: Float.self, capacity: Int(pcmBuffer.frameCapacity)) { srcFloatsForChannel in                 pcmBuffer.floatChannelData?[i].assign(from: srcFloatsForChannel, count: Int(pcmBuffer.frameCapacity))             }         }         return pcmBuffer     } } AudioFrame is: final class AudioFrame: MEFrame {     var timebase = Timebase.defaultValue     var duration: Int64 = 0     var size: Int64 = 0     var position: Int64 = 0     var numberOfSamples = 0     let dataWrap: ByteDataWrap     public init(bufferSize: Int32, channels: Int32) {         dataWrap = ObjectPool.share.object(class: ByteDataWrap.self, key: "AudioData_\(channels)") { ByteDataWrap() }         if dataWrap.size[0] < bufferSize {             dataWrap.size = Array(repeating: Int(bufferSize), count: Int(channels))         }     } ... } and MEFrame is: extension MEFrame {     public var seconds: TimeInterval { cmtime.seconds }     public var cmtime: CMTime { timebase.cmtime(for: position) } }
Posted
by wotson.
Last updated
.
Post not yet marked as solved
7 Replies
11k Views
Hi,, Is there a documentation up for accessing dynamic island (on iPhone 14 Pro) with live activities? Couldn't find anything. Thanks!
Posted
by wotson.
Last updated
.
Post not yet marked as solved
0 Replies
569 Views
Hi, Is there an app limit or user limit for song matches with ShazamKit? I need to know if I need to limit access or not on my app. If there is a limit, is it per user or per the entire calls made by the app? I am using the matchStreamingBuffer continiously, so it is called every few seconds (with the same match).
Posted
by wotson.
Last updated
.
Post not yet marked as solved
0 Replies
797 Views
Hi, I'm trying to work with WeatherKit. I've added the capability to the App ID as well as the capabilities in Xcode. Still after more than a day, in simulator I get 401 error, and on device even stranger - there weatherFor function is called but NEVER returns or throws an exception. try { let weatherService = WeatherService() let weather = try await weatherService.weather(for: location) print(weather) //never gets called } catch { ... // never called on device, always called on simulator Any one has an idea how to get it to work?
Posted
by wotson.
Last updated
.
Post not yet marked as solved
0 Replies
752 Views
Hi, This is a very pecurliar problem. I have an audio app that plays when being launched. It has CarPlay entitlements, plays from the network and naturally plays in the background. Now, every one in a while the phone launchs the app in the background without notice. Music simply starts to play randomly. I can't determine the cause or the situation in which this reproduces. It might be related to Bluetooth connections, phone calls, CarPlay interactions, network changes or other reasons. I do know the following things for sure: The app is launched from scratch as I have examined remote logs and seen the app is being launched. Pausing the music from control center will kill the app, and it will be relaunching after 2-3 minutes again (and again) Any clues or ideas on why this happens or how to debug it further will be welcome. Thank you..!
Posted
by wotson.
Last updated
.
Post not yet marked as solved
0 Replies
695 Views
Hi, I would like to enable the user to use a custom Siri shortcut defined using INUIAddVoiceShortcutViewController and a matching UserActivity - to skip Lock Screen authentication. Is that possible? It looks like a Custom Intent might be the only way to define this.
Posted
by wotson.
Last updated
.
Post not yet marked as solved
0 Replies
626 Views
Hi, When activating AirPlay it seems MPVolumeView disappears. Without any ability to have on-screen slider to control the volume. This seems to be only available on Apple's apps. Am I missing something?
Posted
by wotson.
Last updated
.
Post not yet marked as solved
0 Replies
637 Views
Hi, I have a music app that plays music. From some reason when the navigation app (Waze in this instance) starts to talk, the music stops and doesn't return. When other interruptions happen (messages, voice call) everything works as expected. Any thoughts of what I'm missing?
Posted
by wotson.
Last updated
.