mirror of
https://github.com/IllusionMan1212/lyrics-grabbr.git
synced 2026-10-24 02:12:27 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
197be6330b | ||
|
|
100157a8d4 |
+11
-12
@@ -56,21 +56,19 @@ class NotificationListener : NotificationListenerService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onNotificationPosted(sbn: StatusBarNotification) {
|
override fun onNotificationPosted(sbn: StatusBarNotification) {
|
||||||
if (sbn.packageName == SPOTIFY_PACKAGE) {
|
|
||||||
sendNotificationBroadcast(sbn, applicationContext)
|
sendNotificationBroadcast(sbn, applicationContext)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun getStopServiceNotificationAction(): PendingIntent {
|
private fun getStopServiceNotificationAction(): PendingIntent {
|
||||||
val intent = Intent(MainActivity.ACTION_NOTIFICATION_LISTENER_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
val intent = Intent(MainActivity.ACTION_NOTIFICATION_LISTENER_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
|
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||||
return pendingIntent
|
return pendingIntent
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startForegroundService() {
|
private fun startForegroundService() {
|
||||||
val notification: Notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
val notification: Notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||||
.setContentTitle("Service Running")
|
.setContentTitle("Service Running")
|
||||||
.setContentText("Play some songs on spotify to get lyrics")
|
.setContentText("Play some songs on a supported player to get lyrics")
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setShowWhen(false)
|
.setShowWhen(false)
|
||||||
.addAction(R.drawable.ic_notification, "Stop Service", getStopServiceNotificationAction())
|
.addAction(R.drawable.ic_notification, "Stop Service", getStopServiceNotificationAction())
|
||||||
@@ -103,19 +101,21 @@ class NotificationListener : NotificationListenerService() {
|
|||||||
private fun getCurrentNotifications(context: Context) {
|
private fun getCurrentNotifications(context: Context) {
|
||||||
val sbns = activeNotifications
|
val sbns = activeNotifications
|
||||||
for (sbn in sbns) {
|
for (sbn in sbns) {
|
||||||
if (sbn.packageName == SPOTIFY_PACKAGE) {
|
|
||||||
sendNotificationBroadcast(sbn, context)
|
sendNotificationBroadcast(sbn, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun sendNotificationBroadcast(sbn: StatusBarNotification, context: Context) {
|
private fun sendNotificationBroadcast(sbn: StatusBarNotification, context: Context) {
|
||||||
// get the media session stuff
|
// get the media session stuff
|
||||||
val mediaSessionToken = sbn.notification.extras.getParcelable<MediaSession.Token>(Notification.EXTRA_MEDIA_SESSION)
|
val mediaSessionToken = sbn.notification.extras.getParcelable<MediaSession.Token>(Notification.EXTRA_MEDIA_SESSION)
|
||||||
val mediaCtrl = mediaSessionToken?.let { MediaController(context, it) }
|
if (mediaSessionToken == null) {
|
||||||
val duration = mediaCtrl?.metadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.div(1000)
|
return
|
||||||
val playbackState = mediaCtrl?.playbackState?.state
|
}
|
||||||
val albumArt = mediaCtrl?.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
|
||||||
|
val mediaCtrl = mediaSessionToken.let { MediaController(context, it) }
|
||||||
|
val duration = mediaCtrl.metadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.div(1000)
|
||||||
|
val playbackState = mediaCtrl.playbackState?.state
|
||||||
|
val albumArt = mediaCtrl.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||||
|
|
||||||
// Retrieve package name to set as title.
|
// Retrieve package name to set as title.
|
||||||
val packageName = sbn.packageName
|
val packageName = sbn.packageName
|
||||||
@@ -134,7 +134,7 @@ class NotificationListener : NotificationListenerService() {
|
|||||||
if (playbackState == PlaybackState.STATE_PAUSED) {
|
if (playbackState == PlaybackState.STATE_PAUSED) {
|
||||||
val notification: Notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
val notification: Notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||||
.setContentTitle("Service Running")
|
.setContentTitle("Service Running")
|
||||||
.setContentText("Play some songs on spotify to get lyrics")
|
.setContentText("Play some songs on a supported player to get lyrics")
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setShowWhen(false)
|
.setShowWhen(false)
|
||||||
.addAction(R.drawable.ic_notification, "Stop Service", getStopServiceNotificationAction())
|
.addAction(R.drawable.ic_notification, "Stop Service", getStopServiceNotificationAction())
|
||||||
@@ -173,7 +173,6 @@ class NotificationListener : NotificationListenerService() {
|
|||||||
const val NOTIFICATION_PACKAGE_DURATION = "package_duration"
|
const val NOTIFICATION_PACKAGE_DURATION = "package_duration"
|
||||||
const val NOTIFICATION_ID = 12251999
|
const val NOTIFICATION_ID = 12251999
|
||||||
const val NOTIFICATION_CHANNEL_ID = "Lyrics"
|
const val NOTIFICATION_CHANNEL_ID = "Lyrics"
|
||||||
const val SPOTIFY_PACKAGE = "com.spotify.music"
|
|
||||||
const val START_FOREGROUND_SERVICE_ACTION = "START_SERVICE"
|
const val START_FOREGROUND_SERVICE_ACTION = "START_SERVICE"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class _LyricsPageState extends State<LyricsPage> {
|
|||||||
lyrics = fullLyrics;
|
lyrics = fullLyrics;
|
||||||
fetching = false;
|
fetching = false;
|
||||||
});
|
});
|
||||||
// print(thing);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
|
|
||||||
import 'lyrics.dart';
|
import 'lyrics.dart';
|
||||||
|
|
||||||
@@ -135,6 +136,17 @@ class _SearchResultState extends State<SearchResult> {
|
|||||||
width: 75,
|
width: 75,
|
||||||
height: 75,
|
height: 75,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
|
errorBuilder: (context, error, stackTrace) {
|
||||||
|
Fluttertoast.showToast(
|
||||||
|
msg: 'Failed to load album art for: ${widget.title}',
|
||||||
|
toastLength: Toast.LENGTH_LONG);
|
||||||
|
return const Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 75,
|
||||||
|
height: 75,
|
||||||
|
child: Icon(Icons.broken_image, size: 40)),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Flexible(
|
Flexible(
|
||||||
|
|||||||
@@ -128,6 +128,13 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
fluttertoast:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: fluttertoast
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "8.0.9"
|
||||||
html:
|
html:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
+2
-1
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
|
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
|
||||||
# Read more about iOS versioning at
|
# Read more about iOS versioning at
|
||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
version: 0.1.1+1
|
version: 0.2.1+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.16.1 <3.0.0"
|
sdk: ">=2.16.1 <3.0.0"
|
||||||
@@ -34,6 +34,7 @@ dependencies:
|
|||||||
flutter_local_notifications: ^9.3.2
|
flutter_local_notifications: ^9.3.2
|
||||||
url_launcher: ^6.0.20
|
url_launcher: ^6.0.20
|
||||||
web_scraper: ^0.1.4
|
web_scraper: ^0.1.4
|
||||||
|
fluttertoast: ^8.0.9
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user