Skip to content

Commit

Permalink
add import playlist function and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Cordero committed Feb 4, 2023
1 parent 6452a79 commit 5bdfe8e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
10 changes: 10 additions & 0 deletions lib/core/file_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ class FileUtils {
}
}

static void importPlaylist(List<File> files) async {
String dir = await constants.playlistsDirectory();

for (File file in files) {
String filePath = p.join(dir, basename(file.path));

await file.copy(filePath);
}
}

static void importBibles(List<File> files) async {
for (File file in files) {
BibleParser(file.path).parse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freecps/core/constants.dart';
import 'package:freecps/core/helper_functions.dart';
import 'package:freecps/media_center/widgets/song_preview.dart';
import 'package:freecps/media_center/widgets/video_preview.dart';
import 'package:path/path.dart';

import '../../models/saved_verse_slides.dart';
import '../../models/song_model.dart';

class MediaCenterPlaylistPreviewNotifier extends StateNotifier<Widget> {
MediaCenterPlaylistPreviewNotifier(dynamic args) : super(Container()) {
_preview(args);
_preview(args);
}

void _preview(dynamic args) {
Expand All @@ -40,9 +39,13 @@ class MediaCenterPlaylistPreviewNotifier extends StateNotifier<Widget> {

for (var e in videoFileExtensions) {
if (args.toLowerCase().contains(e)) {
String filePath = join(await videosDirectory(), args);
//String filePath = join(await videosDirectory(), args);

state = VideoPreview(filePath: filePath);
// TODO show thumbnail
state = const Center(
child: Text('Video Preview is currently not supported\n https://github.com/alexmercerind/dart_vlc/issues/357'),
);
//state = VideoPreview(filePath: filePath);

return;
}
Expand Down
18 changes: 15 additions & 3 deletions lib/media_center/tabs/media_center_playlists_tab.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freecps/core/file_utils.dart';
import 'package:freecps/media_center/widgets/playlist_preview_panel.dart';

import '../../core/constants.dart' as constants;
import '../../core/file_utils.dart';
import '../../core/providers_declaration.dart';
import '../../models/playlist_model.dart';
import '../media_center_providers.dart';
import '../widgets/playlist_preview_panel.dart';

class MediaCenterPlaylistsTab extends ConsumerWidget {
const MediaCenterPlaylistsTab({
Expand Down Expand Up @@ -99,7 +101,17 @@ class MediaCenterPlaylistsTab extends ConsumerWidget {
width: 50,
),
ElevatedButton(
onPressed: () async {},
onPressed: () async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
allowMultiple: true,
type: FileType.custom,
allowedExtensions: constants.playlistFileExtension,
);

if (result == null) return;

FileUtils.importPlaylist(FileUtils.filePickerResultToFile(result));
},
child: const Text('Import'),
),
],
Expand Down
4 changes: 2 additions & 2 deletions lib/media_center/tabs/media_center_songs_tab.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freecps/media_center/widgets/song_preview.dart';
import 'package:freecps/media_center/widgets/song_slide_preview.dart';

import '../../core/constants.dart' as constants;
import '../../core/file_utils.dart';
import '../../core/providers_declaration.dart';
import '../../models/song_model.dart';
import '../media_center_providers.dart';
import '../widgets/song_preview.dart';
import '../widgets/song_slide_preview.dart';

class MediaCenterSongsTab extends ConsumerWidget {
const MediaCenterSongsTab({
Expand Down
3 changes: 2 additions & 1 deletion lib/media_center/widgets/video_preview.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:math';

import 'package:dart_vlc/dart_vlc.dart';
import 'package:flutter/material.dart';
Expand All @@ -17,7 +18,7 @@ class _VideoPreviewState extends State<VideoPreview> {

@override
void initState() {
player = Player(id: 3445);
player = Player(id: Random().nextInt(999));
player.setPlaylistMode(PlaylistMode.loop);
player.open(Media.file(File(widget.filePath)));
super.initState();
Expand Down
6 changes: 3 additions & 3 deletions lib/windows/projection_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class _ProjectionWindowState extends State<ProjectionWindow> {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
floatingActionButton: FloatingActionButton(onPressed: () {}),
floatingActionButtonLocation: FloatingActionButtonLocation.miniStartFloat,
// floatingActionButton: FloatingActionButton(onPressed: () {}),
// floatingActionButtonLocation: FloatingActionButtonLocation.miniStartFloat,
body: SizedBox.expand(
child: Stack(
children: [
Expand Down Expand Up @@ -63,7 +63,7 @@ class _ProjectionWindowState extends State<ProjectionWindow> {

@override
void initState() {
player = Player(id: 1);
player = Player(id: 9999);
player.setPlaylistMode(PlaylistMode.loop);

DesktopMultiWindow.setMethodHandler(
Expand Down

0 comments on commit 5bdfe8e

Please sign in to comment.