Skip to content

Commit

Permalink
Merge pull request #31 from resucutie/no-mediakit
Browse files Browse the repository at this point in the history
Replace media_kit with fvp
  • Loading branch information
resucutie authored Oct 12, 2024
2 parents 86af695 + 41efad4 commit 0f2c58b
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 232 deletions.
40 changes: 28 additions & 12 deletions lib/components/video_view.dart
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
import 'dart:io';

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:localbooru/utils/platform_tools.dart';
import 'package:mime/mime.dart';
import 'package:video_player/video_player.dart';

class VideoView extends StatefulWidget {
const VideoView(this.path, {Key? key}) : super(key: key);
const VideoView(this.path, {super.key, this.showControls = true});

final String path;
final bool showControls;

@override
State<VideoView> createState() => VideoViewState();
}

class VideoViewState extends State<VideoView> {
late final player = Player();
late VideoPlayerController _videoController;
late ChewieController _chewieController;
bool _isLoaded = false;

late final controller = VideoController(player);

@override
void initState() {
super.initState();

player.open(Media(widget.path), play: lookupMimeType(widget.path) == "image/gif");
player.setPlaylistMode(PlaylistMode.single);
_videoController = VideoPlayerController.file(File(widget.path))
..initialize().then((value) {
_chewieController = ChewieController(
videoPlayerController: _videoController,
autoPlay: true,
looping: true,
allowFullScreen: false, // apparently full screen calls dispose()
showControls: widget.showControls
);
setState(() {
_isLoaded = true;
});
},);
}

@override
void dispose() {
player.dispose();
_videoController.dispose();
_chewieController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
child: Video(controller: controller, fill: Colors.transparent),
return AspectRatio(
aspectRatio: _videoController.value.aspectRatio,
child: _isLoaded ? Chewie(controller: _chewieController,) : const SizedBox(height: 0,)
);
}
}
8 changes: 4 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
import 'package:localbooru/api/index.dart';
import 'package:localbooru/components/builders.dart';
import 'package:localbooru/components/dialogs/download_dialog.dart';
import 'package:localbooru/components/drawer.dart';
import 'package:localbooru/components/housings.dart';
import 'package:localbooru/components/window_frame.dart';
import 'package:localbooru/utils/constants.dart';
Expand All @@ -31,14 +30,15 @@ import 'package:localbooru/views/settings/booru_settings/tag_types.dart';
import 'package:localbooru/views/settings/index.dart';
import 'package:localbooru/views/settings/overall_settings.dart';
import 'package:localbooru/views/test_playground.dart';
import 'package:media_kit/media_kit.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:go_router/go_router.dart';
import 'package:localbooru/views/permissions.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';

import 'package:fvp/fvp.dart' as fvp;

void main() async {
// custom error screen because release just yeets the error messages in favor of a gray screen
ErrorWidget.builder = (FlutterErrorDetails details) {
Expand Down Expand Up @@ -76,9 +76,9 @@ void main() async {
});
}

runApp(const App());
fvp.registerWith();

MediaKit.ensureInitialized();
runApp(const App());

// if(isDesktop()) {
// doWhenWindowReady(() {
Expand Down
30 changes: 14 additions & 16 deletions lib/utils/compressor.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:ffmpeg_cli/ffmpeg_cli.dart';
import 'package:flutter/material.dart';
import 'package:image_compression/image_compression.dart' as imageCompression;
import 'package:image_compression/image_compression_io.dart';
import 'package:localbooru/api/index.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:mime/mime.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
Expand Down Expand Up @@ -42,12 +39,12 @@ Future<ImageFile> compressToThumbnail(File file,) async {
ImageFile input;

final mime = lookupMimeType(file.path);
if(mime!.startsWith("video/") || mime == "image/gif") {
/*if(mime!.startsWith("video/") || mime == "image/gif") {
input = ImageFile(
filePath: file.path,
rawBytes: await getVideoFirstFrame(file.path)
);
} else if(mime.startsWith("image/")) {
} else*/ if(mime!.startsWith("image/")) {
input = ImageFile(
filePath: file.path,
rawBytes: await file.readAsBytes()
Expand All @@ -60,22 +57,23 @@ Future<ImageFile> compressToThumbnail(File file,) async {
return compressedImage;
}

Future<Uint8List> getVideoFirstFrame(String path) async {
final player = Player();
final controller = VideoController(player); // has to be created according to https://github.com/media-kit/media-kit/issues/419#issuecomment-1703855470
// update to not depend on media_kit
// Future<Uint8List> getVideoFirstFrame(String path) async {
// final player = Player();
// final controller = VideoController(player); // has to be created according to https://github.com/media-kit/media-kit/issues/419#issuecomment-1703855470

await player.open(Media(path), play: false);
await controller.waitUntilFirstFrameRendered;
await Future.delayed(const Duration(milliseconds: 500)); // idk why but this works
// await player.open(Media(path), play: false);
// await controller.waitUntilFirstFrameRendered;
// await Future.delayed(const Duration(milliseconds: 500)); // idk why but this works

await player.seek(Duration.zero);
// await player.seek(Duration.zero);

final bytes = await player.screenshot();
// final bytes = await player.screenshot();

player.dispose();
// player.dispose();

return bytes!;
}
// return bytes!;
// }


Future<File> compress(File file) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/views/image_manager/components/image_upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ImageUploadForm extends StatelessWidget {
if(state.value.isEmpty) {
return const Icon(Icons.add);
} else {
if(lookupMimeType(state.value)!.startsWith("video/")) return IgnorePointer(child: VideoView(state.value),);
if(lookupMimeType(state.value)!.startsWith("video/")) return IgnorePointer(child: VideoView(state.value, showControls: false,),);
return Image(
image: ResizeImage(
FileImage(File(state.value)),
Expand Down
12 changes: 4 additions & 8 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#include "generated_plugin_registrant.h"

#include <dynamic_color/dynamic_color_plugin.h>
#include <fvp/fvp_plugin.h>
#include <irondash_engine_context/irondash_engine_context_plugin.h>
#include <media_kit_libs_linux/media_kit_libs_linux_plugin.h>
#include <media_kit_video/media_kit_video_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <super_native_extensions/super_native_extensions_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
Expand All @@ -19,15 +18,12 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) fvp_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FvpPlugin");
fvp_plugin_register_with_registrar(fvp_registrar);
g_autoptr(FlPluginRegistrar) irondash_engine_context_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "IrondashEngineContextPlugin");
irondash_engine_context_plugin_register_with_registrar(irondash_engine_context_registrar);
g_autoptr(FlPluginRegistrar) media_kit_libs_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "MediaKitLibsLinuxPlugin");
media_kit_libs_linux_plugin_register_with_registrar(media_kit_libs_linux_registrar);
g_autoptr(FlPluginRegistrar) media_kit_video_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "MediaKitVideoPlugin");
media_kit_video_plugin_register_with_registrar(media_kit_video_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
Expand Down
4 changes: 1 addition & 3 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
fvp
irondash_engine_context
media_kit_libs_linux
media_kit_video
screen_retriever
super_native_extensions
url_launcher_linux
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
media_kit_native_event_loop
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down
10 changes: 4 additions & 6 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@ import Foundation

import device_info_plus
import dynamic_color
import fvp
import irondash_engine_context
import media_kit_libs_macos_video
import media_kit_video
import package_info_plus
import path_provider_foundation
import screen_brightness_macos
import screen_retriever
import share_plus
import shared_preferences_foundation
import sqflite
import super_native_extensions
import url_launcher_macos
import video_player_avfoundation
import wakelock_plus
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FvpPlugin.register(with: registry.registrar(forPlugin: "FvpPlugin"))
IrondashEngineContextPlugin.register(with: registry.registrar(forPlugin: "IrondashEngineContextPlugin"))
MediaKitLibsMacosVideoPlugin.register(with: registry.registrar(forPlugin: "MediaKitLibsMacosVideoPlugin"))
MediaKitVideoPlugin.register(with: registry.registrar(forPlugin: "MediaKitVideoPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenBrightnessMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenBrightnessMacosPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
SuperNativeExtensionsPlugin.register(with: registry.registrar(forPlugin: "SuperNativeExtensionsPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
WakelockPlusMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockPlusMacosPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
Loading

0 comments on commit 0f2c58b

Please sign in to comment.