brim-borium / spotify_sdk

Flutter Package to connect the spotify sdk
https://pub.dev/packages/spotify_sdk
Apache License 2.0
153 stars 82 forks source link

MissingPluginException(No implementation found for method listen on channel player_context_subscription) #189

Closed EXEIdeas closed 1 year ago

EXEIdeas commented 1 year ago

Hi, I am using a free Spotify account for development purposes only. I am trying to use this to connect my Flutter iOS application with Spotify. One thing to mention in advance is that the whole code I did is working fine on Android perfectly but not on iPhone. I followed the instructions in the section Setup the iOS SDK of Spotify iOS SDK Quick Start. It connects then returns a token and opens my application and songs start playing on Spotify. I am able to hit the button at the bottom and it also changes the song "I'll Make a Man Out of You" which is linked in the example at https://github.com/brim-borium/spotify_sdk/tree/main/example

Well I just copied example project files in my project and use my ClientID and RedirectURL and it works well in Andriod but when I run it on iOS it started giving me the below error...

AppRemote: Connecting...
[connection] nw_socket_handle_socket_event [C1.1.1:1] Socket SO_ERROR [61: Connection refused]
AppRemote: Established a connection to the Spotify app.
AppRemote: Authenticated with the Spotify app.
AppRemote: Established a session with the Spotify app.
flutter: \^[[38;5;12m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;12m│ #0   _SpotifyExampleState.setStatus (package:runwith/screens/SpotifyExample/Debugging.dart:647:13)<…>
flutter: \^[[38;5;12m│ #1   _SpotifyExampleState.getAccessToken (package:runwith/screens/SpotifyExample/Debugging.dart:459:7)<…>
flutter: \^[[38;5;12m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
flutter: \^[[38;5;12m│ 22:26:44.966 (+0:01:30.499038)<…>
flutter: \^[[38;5;12m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
flutter: \^[[38;5;12m│ 💡 Got a token: BQDPjhNCDTPalqK71CNYU2PGI_VF8ejg7PzaQK7e01p2mnpi4smf7bX5SCANXUd211T84grf_DgcKKmuWN7KbOGPy-sKESYmgKG59_4EC0MKX21E6mZ9UVPaH58D4ovtKg33DJRU9FRJEWODFOISYGIUU09S328EWEYYWR802384WUDJUF98YCOIFIHSDJHCJ38EYIEDN90WEUF0UJDOFCJW09R0JFOIJU0R9U0rlumS_GSMx-OR0arQdE7ayy-OJxIDXCyPIZ8o0NlQtQdPwoJ7ZIxT4vzmNj4kj4JnbWxiy2V5v6NdMhUY8qYLk7YmZSdY2oL8CZe9oMOGQSoXR7cJA<…>
flutter: \^[[38;5;12m└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>

======== Exception caught by services library ======================================================
The following MissingPluginException was thrown while activating platform stream on channel player_state_subscription:
MissingPluginException(No implementation found for method listen on channel player_state_subscription)

When the exception was thrown, this was the stack: 
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:313:7)
<asynchronous suspension>
#1      EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:662:9)
<asynchronous suspension>
====================================================================================================

======== Exception caught by services library ======================================================
The following MissingPluginException was thrown while activating platform stream on channel player_context_subscription:
MissingPluginException(No implementation found for method listen on channel player_context_subscription)

When the exception was thrown, this was the stack: 
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:313:7)
<asynchronous suspension>
#1      EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:662:9)
<asynchronous suspension>
====================================================================================================

So my main bug is MissingPluginException(No implementation found for method listen on channel player_state_subscription) & MissingPluginException(No implementation found for method listen on channel player_context_subscription) that was not showing earlier and crashing the app in iOS then I did this https://www.appsloveworld.com/coding/ios/1092/gcdwebserver-always-aborts-on-options-check then I am able to see upper error code.

Here is the rest of the required details...

Other Plugin

dependencies:
  flutter:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  # ThirdParty Dependencies Added Manually
  shared_preferences: ^2.0.15
  google_fonts: ^3.0.1
  http: ^0.13.4
  http_interceptor: ^1.0.2
  dio: ^4.0.4
  retrofit: ^3.0.0
  flutter_datetime_picker: ^1.5.1
  intl: ^0.17.0
  fluttertoast: ^8.0.9
  sn_progress_dialog: ^1.1.3
  flutter_native_splash: ^2.2.14
  flutter_launcher_icons: ^0.10.0
  animated_splash_screen: ^1.3.0
  country_code_picker: ^2.0.2
  country_codes: ^2.2.0
  animated_bottom_navigation_bar: ^1.1.0
  carousel_slider: ^4.1.1
  csc_picker: ^0.2.6
  google_maps_flutter: ^2.2.0
  location: ^4.4.0
  permission_handler: ^9.2.0
  path_provider: ^2.0.8
  provider: ^6.0.1
  flutter_polyline_points: 1.0.0
  share_plus: ^4.0.4
  flutter_background_service: ^2.4.5
  device_info_plus: ^8.0.0
  sensors_plus: ^2.0.1
  image_picker: ^0.8.4+8
  better_player: any
  flutter_google_places: 0.3.0
  google_maps_webservice: ^0.0.19
  google_api_headers: ^1.5.0
  custom_marker: 1.0.0
  pull_to_refresh: ^2.0.0
  spotify_sdk: ^2.3.1
  flutter_dotenv: ^5.0.2
  cast: ^1.1.1
  logger: ^1.1.0
  flutter_vlc_player: ^7.1.4
  app_settings: ^4.1.1
  number_to_words: ^1.0.0
  just_audio: ^0.9.31
  webview_flutter: ^3.0.4
  flutter_easyloading: ^3.0.5
  flutter_html: ^3.0.0-alpha.6
  just_the_tooltip: ^0.0.12
  image: ^3.3.0
  screenshot: ^1.3.0

Fluter Doctor

/Users/my_macbook_username/AndroidStudioProjects/flutter_v3.7.11/bin/flutter doctor --verbose
[!] Flutter (Channel stable, 3.7.11, on macOS 13.3.1 22E261 darwin-arm64, locale en-PK)
    • Flutter version 3.7.11 on channel stable at /Users/my_macbook_username/AndroidStudioProjects/flutter_v3.7.11
    ! The flutter binary is not on your path. Consider adding /Users/my_macbook_username/AndroidStudioProjects/flutter_v3.7.11/bin to your path.
    ! The dart binary is not on your path. Consider adding /Users/my_macbook_username/AndroidStudioProjects/flutter_v3.7.11/bin to your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f72efea43c (3 weeks ago), 2023-04-11 11:57:21 -0700
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/exeideasmy_macbook_usernameLibrary/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Connected device (3 available)
    • SM A325F (mobile) • RF8R509QMYF • android-arm64  • Android 13 (API 33)
    • macOS (desktop)   • macos       • darwin-arm64   • macOS 13.3.1 22E261 darwin-arm64
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 112.0.5615.137

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
Process finished with exit code 0

Target Platform, Version & Device

Development OS

UPDATE:

After trying multiple ways, I found out that "flutter_background_service" plugin is breaking this Spotify Player State Stream. When I stop background service then it is working fine but when I start background service before the Spotify connection then it is giving me this error. Now how to keep both?

brim-borium commented 1 year ago

@EXEIdeas Hi sorry to hear that iOS does not work for you. @fotiDim can you have a look at this?

fotiDim commented 1 year ago

@EXEIdeas, can you provide a minimal example that replicates the issue? Ideally, based on the example app.

EXEIdeas commented 1 year ago

HI @fotiDim & @brim-borium Sorry for the late reply, here is the minimum viable problem example. https://github.com/EXEIdeas/spotify_sdk-example

EXEIdeas commented 1 year ago

@fotiDim @brim-borium Any Update...???

HI @fotiDim & @brim-borium Sorry for the late reply, here is the minimum viable problem example. https://github.com/EXEIdeas/spotify_sdk-example

EXEIdeas commented 1 year ago

@fotiDim @brim-borium Any Update...???

HI @fotiDim & @brim-borium Sorry for the late reply, here is the minimum viable problem example. https://github.com/EXEIdeas/spotify_sdk-example

fotiDim commented 1 year ago

@EXEIdeas not yet. I will try to have a look within the weekend.

jasminder commented 1 year ago

This was posted on May 2. Any updates. Although the Spotify works with few minor issues like Player State is just bad and doesnt update sometimes, but this exception is consistent and is possibly crashing the app too.

EXEIdeas commented 1 year ago

@jasminder Still have the issue. It is working fine until I am not starting background service. Then after starting the background service, it started giving me the above error. What I think is that MethodChannel names are messing up...

fotiDim commented 1 year ago

@jasminder are you also using flutter_background_service?

jasminder commented 1 year ago

@fotiDim No, we are not using flutter_background_service. In our case, Spotify does work, but, it crashes the app as we have tried the app by removing this package and the app works fine. This package is slowing down the app and even crashing it, while continuously throwing the listen, cancel exceptions.

EXEIdeas commented 1 year ago

@jasminder @fotiDim Yes, this is the problem. It is happening may be due to the same channel name as flutter_background_service also use channels with name like play, pause etc Can you look into that way?

rohitsangwan01 commented 1 year ago

@EXEIdeas please check if this pr fixes your issue

rohitsangwan01 commented 1 year ago

@jasminder you can use (listen/cancel) subscribePlayerState() subscribePlayerContext() streams only after connecting successfully to Spotify

fotiDim commented 1 year ago

We can reopen if the issue was not solved with the merged PR. Until there is a new release you can point your pubspec to the master branch of this repo.

EXEIdeas commented 1 year ago

@fotiDim Well I am using spotify_sdk: ^2.3.1 so I am getting Because runwith depends on spotify_sdk from git which requires SDK version >=3.0.6 <4.0.0, version solving failed. when trying to add below in pubspec.ymal...

spotify_sdk:
    git:
      url: https://github.com/brim-borium/spotify_sdk.git
      ref: main
rohitsangwan01 commented 1 year ago

@EXEIdeas you have to update your dart sdk version (>=3.0.6 <4.0.0 ) to use latest spotify_sdk

EXEIdeas commented 1 year ago

@rohitsangwan01 @fotiDim @jasminder @brim-borium Thanks to all for your support and help. Finally it is working with flutter_background_service with using lates flutter and dart. Now release it officially as it will help others too. Have a Nice Day.

brim-borium commented 1 year ago

A new version has been released and can be used from pub.dev: https://pub.dev/packages/spotify_sdk/versions/3.0.0-dev.3