misiio / flutter_music_kit

MIT License
12 stars 11 forks source link

Not able to get developer token in Androdi #2

Open assetmoney-tejesh opened 1 year ago

assetmoney-tejesh commented 1 year ago

I have successfully integrated in IOS but the same implementation is throwing an error in Android

Here is the error :

PlatformException(requestDeveloperToken, null, java.lang.reflect.InvocationTargetException I/flutter ( 7106): at java.lang.reflect.Method.invoke(Native Method) I/flutter ( 7106): at app.misi.music_kit.ChannelHandler.onMethodCall(ChannelHandler.kt:123) I/flutter ( 7106): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258) I/flutter ( 7106): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) I/flutter ( 7106): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)

Let me know if there is a way to solve this.

MrChausson commented 2 months ago

Just had the same error today. Let me know if you fixed it

NSRitz999 commented 1 month ago

Hi! I was looking into this recently and noticed that on the Android side of things, requestDeveloperToken() does not generate a developer token like IOS implementation. Instead, you'll have to create an apple music developer token from scratch. Thankfully there are some good resources out there for this, such as the official apple documentation and this github repository.

After you have the token, you'll have to initialize MusicKit differently from IOS by manually calling the MusicKit.initialize() method. Here's an example of what that code might look like:

class _MyAppState extends State<MyApp> {
    final _musicKitPlugin = MusicKit();
    String? _developerToken = "";
    ...
    @override
    void initState() {
        super.initState();
        initPlatformState();
        // Additional initialization
    }
    ...
    Future<void> initPlatformState() async {
        if (Platform.isAndroid) {
            _developerToken = "<Insert your developer token here>";
            await _musicKitPlugin.initialize(_developerToken);
            // Additional Setup
        }
        ...
    }
...
}