Skip to content

Commit

Permalink
refactor: audio player and youtube client in separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Feb 5, 2023
1 parent a774817 commit ac84942
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 24 deletions.
1 change: 1 addition & 0 deletions lib/collections/intents.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:spotube/components/player/player_controls.dart';
import 'package:spotube/collections/routes.dart';
import 'package:spotube/models/logger.dart';
import 'package:spotube/provider/playlist_queue_provider.dart';
import 'package:spotube/services/audio_player.dart';
import 'package:spotube/utils/platform.dart';
import 'package:window_manager/window_manager.dart';

Expand Down
11 changes: 5 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import 'package:spotube/entities/cache_track.dart';
import 'package:spotube/collections/routes.dart';
import 'package:spotube/collections/intents.dart';
import 'package:spotube/models/logger.dart';
import 'package:spotube/provider/audio_player_provider.dart';
import 'package:spotube/provider/downloader_provider.dart';
import 'package:spotube/provider/user_preferences_provider.dart';
import 'package:spotube/provider/youtube_provider.dart';
import 'package:spotube/services/audio_player.dart';
import 'package:spotube/services/pocketbase.dart';
import 'package:spotube/services/youtube.dart';
import 'package:spotube/themes/dark_theme.dart';
import 'package:spotube/themes/light_theme.dart';
import 'package:spotube/utils/platform.dart';
Expand Down Expand Up @@ -147,7 +147,7 @@ void main(List<String> rawArgs) async {
return Downloader(
ref,
queueInstance,
yt: ref.watch(youtubeProvider),
yt: youtube,
downloadPath: ref.watch(
userPreferencesProvider.select(
(s) => s.downloadLocation,
Expand Down Expand Up @@ -258,12 +258,11 @@ class SpotubeState extends ConsumerState<Spotube> with WidgetsBindingObserver {
ref.watch(userPreferencesProvider.select((s) => s.accentColorScheme));
final backgroundMaterialColor = ref
.watch(userPreferencesProvider.select((s) => s.backgroundColorScheme));
final player = ref.watch(audioPlayerProvider);
final youtube = ref.watch(youtubeProvider);

/// For enabling hot reload for audio player
useEffect(() {
return () {
player.dispose();
audioPlayer.dispose();
youtube.close();
};
}, []);
Expand Down
2 changes: 1 addition & 1 deletion lib/models/spotube_track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'package:spotube/extensions/video.dart';
import 'package:spotube/extensions/album_simple.dart';
import 'package:spotube/extensions/artist_simple.dart';
import 'package:spotube/models/track.dart';
import 'package:spotube/provider/playlist_queue_provider.dart';
import 'package:spotube/provider/user_preferences_provider.dart';
import 'package:spotube/services/pocketbase.dart';
import 'package:spotube/services/youtube.dart';
import 'package:spotube/utils/platform.dart';
import 'package:spotube/utils/primitive_utils.dart';
import 'package:spotube/utils/service_utils.dart';
Expand Down
6 changes: 0 additions & 6 deletions lib/provider/audio_player_provider.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/provider/downloader_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:spotube/components/shared/dialogs/replace_downloaded_dialog.dart
import 'package:spotube/models/logger.dart';
import 'package:spotube/models/spotube_track.dart';
import 'package:spotube/provider/user_preferences_provider.dart';
import 'package:spotube/provider/youtube_provider.dart';
import 'package:spotube/services/youtube.dart';
import 'package:spotube/utils/type_conversion_utils.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart' hide Comment;

Expand Down Expand Up @@ -165,7 +165,7 @@ final downloaderProvider = ChangeNotifierProvider(
return Downloader(
ref,
queueInstance,
yt: ref.watch(youtubeProvider),
yt: youtube,
downloadPath: ref.watch(
userPreferencesProvider.select(
(s) => s.downloadLocation,
Expand Down
4 changes: 1 addition & 3 deletions lib/provider/playlist_queue_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:spotube/models/spotube_track.dart';
import 'package:spotube/extensions/track.dart';
import 'package:spotube/provider/blacklist_provider.dart';
import 'package:spotube/provider/user_preferences_provider.dart';
import 'package:spotube/services/audio_player.dart';
import 'package:spotube/services/linux_audio_service.dart';
import 'package:spotube/services/mobile_audio_service.dart';
import 'package:spotube/utils/persisted_state_notifier.dart';
Expand All @@ -16,9 +17,6 @@ import 'package:spotube/utils/type_conversion_utils.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart' hide Playlist;
import 'package:collection/collection.dart';

final audioPlayer = AudioPlayer();
final youtube = YoutubeExplode();

class PlaylistQueue {
final Set<Track> tracks;
final Set<Track> tempTracks;
Expand Down
4 changes: 0 additions & 4 deletions lib/provider/youtube_provider.dart

This file was deleted.

3 changes: 3 additions & 0 deletions lib/services/audio_player.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:audioplayers/audioplayers.dart';

final audioPlayer = AudioPlayer();
1 change: 1 addition & 0 deletions lib/services/linux_audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:spotube/provider/dbus_provider.dart';
import 'package:spotube/models/spotube_track.dart';
import 'package:spotube/provider/playlist_queue_provider.dart';
import 'package:spotube/services/audio_player.dart';
import 'package:spotube/utils/type_conversion_utils.dart';
import 'package:window_manager/window_manager.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/services/mobile_audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import 'package:audio_service/audio_service.dart';
import 'package:audio_session/audio_session.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:spotube/provider/playlist_queue_provider.dart';
import 'package:spotube/services/audio_player.dart';

class MobileAudioService extends BaseAudioHandler {
AudioSession? session;
final PlaylistQueueNotifier playlistNotifier;
final PlaylistQueueNotifier playlistNotifier;


PlaylistQueue? get playlist => playlistNotifier.state;

MobileAudioService(this.playlistNotifier) {
Expand Down
3 changes: 3 additions & 0 deletions lib/services/youtube.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:youtube_explode_dart/youtube_explode_dart.dart';

final youtube = YoutubeExplode();

0 comments on commit ac84942

Please sign in to comment.