KRTirtho / spotube

🎧 Open source Spotify client that doesn't require Premium nor uses Electron! Available for both desktop & mobile!
https://spotube.krtirtho.dev/
Other
30.39k stars 1.25k forks source link

Feature Request #1027

Open abhinavanand-fed opened 10 months ago

abhinavanand-fed commented 10 months ago

Is there an existing issue for this?

It would be good if the Discord rich presence resembles Spotify's rich presence. Not an exact copy, but there should be an option to showcase music playback from the user's profile.

spotify Spotube

Suggested solution

This might help you.

import 'dart:async';
import 'package:discord_rpc/discord_rpc.dart' as discord_rpc;

void main() {
  discord_rpc.initialize('YOUR_CLIENT_ID');

  // Define a custom URI that your application can handle
  final playButtonUri = 'yourmusicapp://play';

  discord_rpc.updatePresence(
    discord_rpc.Presence(
      details: 'Listening to Music',
      state: 'Song Title',
      largeImageKey: 'spotify',
      largeImageText: 'Your Software Name',
      buttons: [
        discord_rpc.Button(label: 'Play', url: playButtonUri),
      ],
    ),
  );

  // Optional: Set up a periodic timer to keep the presence updated
  Timer.periodic(Duration(seconds: 15), (timer) {
    discord_rpc.updatePresence(
      discord_rpc.Presence(
        details: 'Listening to Music',
        state: 'Song Title',
        largeImageKey: 'spotify',
        largeImageText: 'Your Software Name',
        buttons: [
          discord_rpc.Button(label: 'Play', url: playButtonUri),
        ],
      ),
    );
  });

  // Ensure to close the connection when your application exits
  // This is a simple console app example; in a real application, handle this properly
  // For web applications, use window.onUnload or similar
  ProcessSignal.sigint.watch().listen((_) {
    discord_rpc.shutdown();
    exit(0);
  });
}

Useful resources

No response

Additional information

No response

github-actions[bot] commented 10 months ago

Potential duplicates:

github-actions[bot] commented 10 months ago

Potential duplicates:

KaaaooS commented 10 months ago

Yeah,and maybe show the album cover,thats a so good extra