Skip to content

Commit

Permalink
fix: correctly use discord rpc meta data (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Oct 21, 2024
1 parent 728caf8 commit 26242bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
17 changes: 9 additions & 8 deletions lib/expose/expose_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'dart:async';

import 'package:flutter_discord_rpc/flutter_discord_rpc.dart';

import '../constants.dart';

class ExposeService {
ExposeService({required FlutterDiscordRPC? discordRPC})
: _discordRPC = discordRPC;
Expand All @@ -15,8 +13,10 @@ class ExposeService {
_discordRPC?.isConnectedStream ?? Stream.value(false);

Future<void>? exposeTitleOnline({
required String songDetails,
required String state,
required String line1,
required String line2,
required String line3,
String? imageUrl,
}) async {
try {
if (_discordRPC?.isConnected == false) {
Expand All @@ -26,11 +26,12 @@ class ExposeService {
await _discordRPC?.setActivity(
activity: RPCActivity(
assets: RPCAssets(
largeText: songDetails,
smallText: kAppTitle,
largeText: line3,
largeImage: imageUrl,
),
details: songDetails,
state: state,
details: line1,
state: line2,
activityType: ActivityType.listening,
),
);
}
Expand Down
47 changes: 19 additions & 28 deletions lib/player/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,6 @@ class PlayerService {
_audio = value;
_propertiesChangedController.add(true);
_setMpvMetaData(null);
_exposeAudioOnline(_audio);
}

void _exposeAudioOnline(Audio? audio) {
if (audio?.audioType != null &&
audio?.title != null &&
audio?.artist != null) {
_exposeService.exposeTitleOnline(
songDetails: '${audio!.artist} - ${audio.title}}',
state: switch (audio.audioType!) {
AudioType.local => 'Local Music',
AudioType.podcast => 'Podcast',
AudioType.radio => 'Internet Radio',
},
);
}
}

bool? _isVideo;
Expand Down Expand Up @@ -242,6 +226,12 @@ class PlayerService {
}
_setMediaControlsMetaData(audio: audio!);
_loadColorAndSetRemoteUrl();
await _exposeService.exposeTitleOnline(
line1: audio?.title ?? '',
line2: audio?.artist ?? '',
line3: audio?.album ?? '',
imageUrl: audio?.imageUrl ?? audio?.albumArtUrl,
);
_firstPlay = false;
} on Exception catch (_) {}
}
Expand Down Expand Up @@ -307,23 +297,24 @@ class PlayerService {

if (parsedIcyTitle == null) return;

await _exposeService.exposeTitleOnline(
songDetails: parsedIcyTitle,
state: _audio?.title ?? 'Internet Radio',
);

final songInfo = parsedIcyTitle.splitByDash;
_onlineArtService.fetchAlbumArt(parsedIcyTitle).then(
(albumArt) async {
await _setMediaControlsMetaData(
audio:
(_audio ?? const Audio(audioType: AudioType.radio)).copyWith(
imageUrl: albumArt,
title: songInfo.songName,
artist: songInfo.artist,
),
final mergedAudio =
(_audio ?? const Audio(audioType: AudioType.radio)).copyWith(
imageUrl: albumArt,
title: songInfo.songName,
artist: songInfo.artist,
);
await _setMediaControlsMetaData(audio: mergedAudio);
await _loadColorAndSetRemoteUrl(artUrl: albumArt);

await _exposeService.exposeTitleOnline(
line1: songInfo.songName ?? '',
line2: songInfo.artist ?? '',
line3: _audio?.title ?? 'Internet Radio',
imageUrl: albumArt,
);
},
);
},
Expand Down

0 comments on commit 26242bf

Please sign in to comment.