shinyford / nowplaying

Other
9 stars 11 forks source link

No data received from stream - Android #19

Open AxelJankowski opened 1 month ago

AxelJankowski commented 1 month ago

Hi, I am not receiving any data from stream on Android device. I tried Spotify and Apple Music. Here is part of my manifest with necessary queries:

        <service
            android:name="com.gomes.nowplaying.NowPlayingListenerService"
            android:exported="true"
            android:label="NowPlayingListenerService"
            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
            <intent-filter>
                <action android:name="android.service.notification.NotificationListenerService" />
            </intent-filter>
        </service>
    </application>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

    <queries>
        <package android:name="com.spotify.music" />
        <package android:name="com.google.android.apps.youtube.music" />
        <package android:name="com.apple.android.music" />
        <package android:name="deezer.android.app" />
        <package android:name="com.soundcloud.android" />
        <package android:name="com.aspiro.tidal" />
        <package android:name="com.pandora.android" />
        <package android:name="com.amazon.mp3" />
    </queries>
</manifest>

And here is my implementation in Flutter:

class MusicTrackingService {
  final NowPlaying _nowPlaying;
  final UsersRepository _usersRepository;

  MusicTrackingService(
    this._nowPlaying,
    this._usersRepository,
  );

  void init(AppUser user) async {
    NowPlayingTrack? lastTrack;

    await _nowPlaying.start();
    await _nowPlaying.requestPermissions();
    final bool isEnabled = await _nowPlaying.isEnabled();
    if (!isEnabled) {
      return;
    }
    print('MusicTrackingService started');
    _nowPlaying.stream.listen((NowPlayingTrack track) {
      print('track');
    });
  }
}

After giving the app request permissions the "track" never gets printed. What am I missing?