From dd81d5654c167b934571fb6108639a45e8a1becd Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sun, 5 Jun 2022 15:49:53 +0200 Subject: [PATCH] Can download songs --- README.md | 7 +++ lib/ui/music_player.dart | 36 ++++++++++++- linux/flutter/generated_plugin_registrant.cc | 4 ++ linux/flutter/generated_plugins.cmake | 1 + pubspec.lock | 56 ++++++++++++++++++++ pubspec.yaml | 3 ++ web/index.html | 2 +- 7 files changed, 107 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f63b17..a3a655a 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,12 @@ New generation of music web player for the [music server](https://gitlab.com/pierre42100/musicsserver) written based on Flutter. +### Debugging +Add the following run arguments: + +```bash +--dart-define API_URL= --dart-define API_TOKEN= +``` + ## Screenshot ![screenshot of app](img/screenshot-1.jpg) \ No newline at end of file diff --git a/lib/ui/music_player.dart b/lib/ui/music_player.dart index 058d2a8..8a0c397 100644 --- a/lib/ui/music_player.dart +++ b/lib/ui/music_player.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:music_web_player/api.dart'; import 'package:music_web_player/ui/cover_image.dart'; import 'package:music_web_player/ui/player_web_interface.dart'; +import 'package:url_launcher/url_launcher_string.dart'; import 'package:video_player/video_player.dart'; extension DurationExt on Duration { @@ -191,7 +192,24 @@ class _MusicPlayerState extends State { ), Positioned( - top: 10, right: 10, child: _buildToggleListButton()), + top: 10, + right: 10, + child: fluent.Row( + children: [ + _buildToggleListButton(), + ], + )), + + Positioned( + bottom: 10, + right: 10, + child: fluent.Row( + children: [ + _buildDownloadTrackButton(), + const SizedBox(width: 10), + _buildAboutButton(), + ], + )), ], ), ), @@ -284,6 +302,22 @@ class _MusicPlayerState extends State { ), ); + Widget _buildDownloadTrackButton() => fluent.Button( + onPressed: () => + launchUrlString(currMusic.musicURL, webOnlyWindowName: "_blank"), + child: const fluent.Icon(fluent.FluentIcons.download), + ); + + Widget _buildAboutButton() => fluent.Button( + onPressed: () => showLicensePage( + context: context, + applicationName: "Music Player", + applicationIcon: + const fluent.Icon(FluentIcons.music_note_2_24_regular), + ), + child: const fluent.Icon(fluent.FluentIcons.info), + ); + Widget _buildToggleListButton() => fluent.ToggleButton( checked: _showPlaylist, onChanged: (s) => setState(() => _showPlaylist = s), diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index e71a16d..f6f23bf 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,6 +6,10 @@ #include "generated_plugin_registrant.h" +#include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); + url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2e1de87..f16b4c3 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + url_launcher_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/pubspec.lock b/pubspec.lock index 5b4a8f0..62e281b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -439,6 +439,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.2" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.17" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.17" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" uuid: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 454a7ca..809c3cb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -53,6 +53,9 @@ dependencies: # Audio integration in browser audio_service_web: ^0.1.1 + # Open external links + url_launcher: ^6.1.2 + dev_dependencies: flutter_test: sdk: flutter diff --git a/web/index.html b/web/index.html index 11580ae..10b8eb3 100644 --- a/web/index.html +++ b/web/index.html @@ -29,7 +29,7 @@ - music_web_player + Music Web Player