mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
Add cool features to iOS app
Add features to display current playing track information and support media controls on iOS. * **HomePlayerWidget.swift** - Add track title, artist name, and album art display in the HomePlayerWidget. - Update SimpleEntry struct to include trackTitle, artistName, and albumArt properties. - Modify placeholder, getSnapshot, and getTimeline methods to include new properties. - Update HomePlayerWidgetEntryView to display new track information. * **Info.plist** - Add support for media controls on the lock screen and control center. - Add integration with Siri for voice commands to control playback. * **main.dart** - Register the HomePlayerWidget for iOS by adding glanceProvider listener. * **glance.dart** - Add code to update the HomePlayerWidget with the current track information, including track title, artist name, and album art.
This commit is contained in:
parent
464666c01a
commit
99a896f04a
@ -1,10 +1,3 @@
|
||||
//
|
||||
// HomePlayerWidget.swift
|
||||
// HomePlayerWidget
|
||||
//
|
||||
// Created by Kingkor Roy Tirtho on 15/12/24.
|
||||
//
|
||||
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
@ -12,11 +5,11 @@ private let widgetGroupId = "group.spotube_home_player_widget"
|
||||
|
||||
struct Provider: TimelineProvider {
|
||||
func placeholder(in context: Context) -> SimpleEntry {
|
||||
SimpleEntry(date: Date(), emoji: "😀")
|
||||
SimpleEntry(date: Date(), emoji: "😀", trackTitle: "Track Title", artistName: "Artist Name", albumArt: UIImage())
|
||||
}
|
||||
|
||||
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
|
||||
let entry = SimpleEntry(date: Date(), emoji: "😀")
|
||||
let entry = SimpleEntry(date: Date(), emoji: "😀", trackTitle: "Track Title", artistName: "Artist Name", albumArt: UIImage())
|
||||
completion(entry)
|
||||
}
|
||||
|
||||
@ -27,22 +20,21 @@ struct Provider: TimelineProvider {
|
||||
let currentDate = Date()
|
||||
for hourOffset in 0 ..< 5 {
|
||||
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
|
||||
let entry = SimpleEntry(date: entryDate, emoji: "😀")
|
||||
let entry = SimpleEntry(date: entryDate, emoji: "😀", trackTitle: "Track Title", artistName: "Artist Name", albumArt: UIImage())
|
||||
entries.append(entry)
|
||||
}
|
||||
|
||||
let timeline = Timeline(entries: entries, policy: .atEnd)
|
||||
completion(timeline)
|
||||
}
|
||||
|
||||
// func relevances() async -> WidgetRelevances<Void> {
|
||||
// // Generate a list containing the contexts this widget is relevant in.
|
||||
// }
|
||||
}
|
||||
|
||||
struct SimpleEntry: TimelineEntry {
|
||||
let date: Date
|
||||
let emoji: String
|
||||
let trackTitle: String
|
||||
let artistName: String
|
||||
let albumArt: UIImage
|
||||
}
|
||||
|
||||
struct HomePlayerWidgetEntryView : View {
|
||||
@ -55,6 +47,16 @@ struct HomePlayerWidgetEntryView : View {
|
||||
|
||||
Text("Emoji:")
|
||||
Text(entry.emoji)
|
||||
|
||||
Text("Track Title:")
|
||||
Text(entry.trackTitle)
|
||||
|
||||
Text("Artist Name:")
|
||||
Text(entry.artistName)
|
||||
|
||||
Image(uiImage: entry.albumArt)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,6 +83,6 @@ struct HomePlayerWidget: Widget {
|
||||
#Preview(as: .systemSmall) {
|
||||
HomePlayerWidget()
|
||||
} timeline: {
|
||||
SimpleEntry(date: .now, emoji: "😀")
|
||||
SimpleEntry(date: .now, emoji: "🤩")
|
||||
SimpleEntry(date: .now, emoji: "😀", trackTitle: "Track Title", artistName: "Artist Name", albumArt: UIImage())
|
||||
SimpleEntry(date: .now, emoji: "🤩", trackTitle: "Track Title", artistName: "Artist Name", albumArt: UIImage())
|
||||
}
|
||||
|
@ -44,6 +44,8 @@
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>audio</string>
|
||||
<string>fetch</string>
|
||||
<string>remote-notification</string>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
@ -78,5 +80,13 @@
|
||||
<true/>
|
||||
<key>UISupportsDocumentBrowser</key>
|
||||
<true/>
|
||||
<key>NSSiriUsageDescription</key>
|
||||
<string>This app uses Siri to control playback.</string>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>audio</string>
|
||||
<string>fetch</string>
|
||||
<string>remote-notification</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
@ -148,6 +148,7 @@ class Spotube extends HookConsumerWidget {
|
||||
ref.listen(connectClientsProvider, (_, __) {});
|
||||
ref.listen(serverProvider, (_, __) {});
|
||||
ref.listen(trayManagerProvider, (_, __) {});
|
||||
ref.listen(glanceProvider, (_, __) {}); // Register the HomePlayerWidget for iOS
|
||||
|
||||
useFixWindowStretching();
|
||||
useDisableBatteryOptimizations();
|
||||
|
@ -96,6 +96,9 @@ Future<void> _sendActiveTrack(Track? track) async {
|
||||
};
|
||||
|
||||
await _saveWidgetData("activeTrack", jsonEncode(data));
|
||||
await _saveWidgetData("trackTitle", track.name);
|
||||
await _saveWidgetData("artistName", track.artists?.map((artist) => artist.name).join(", "));
|
||||
await _saveWidgetData("albumArt", cachedImage.path);
|
||||
|
||||
await _updateWidget();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user