Skip to content

Commit

Permalink
feat: take screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
ErBWs committed Dec 8, 2024
1 parent af14245 commit 773bf27
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 65 deletions.
108 changes: 55 additions & 53 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryAddUsageDescription</key>
<string></string>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Kazumi</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>kazumi</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>vlc-x-callback</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Kazumi</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>kazumi</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>vlc-x-callback</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIStatusBarHidden</key>
<false/>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIStatusBarHidden</key>
<false/>
</dict>
</plist>
54 changes: 42 additions & 12 deletions lib/pages/player/player_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import 'package:kazumi/bean/appbar/drag_to_move_bar.dart' as dtb;
import 'package:kazumi/pages/settings/danmaku/danmaku_settings_window.dart';
import 'package:kazumi/utils/constants.dart';
import 'package:kazumi/pages/player/episode_comments_sheet.dart';
import 'package:saver_gallery/saver_gallery.dart';

class PlayerItem extends StatefulWidget {
const PlayerItem(
Expand Down Expand Up @@ -679,6 +680,20 @@ class _PlayerItemState extends State<PlayerItem>
} catch (_) {}
}

Future<void> _handleScreenshot() async {
try {
Uint8List? screenshot = await playerController.mediaPlayer.screenshot(format: 'image/png');
final result = await SaverGallery.saveImage(screenshot!, fileName: DateTime.timestamp().toString(), skipIfExists: true);
if (result.isSuccess) {
SmartDialog.showToast('截图保存到相簿成功');
} else {
SmartDialog.showToast('截图保存失败:${result.errorMessage}');
}
} catch (_) {
SmartDialog.showToast('截图失败');
}
}

@override
void onWindowRestore() {
danmakuController.onClear();
Expand Down Expand Up @@ -1296,19 +1311,34 @@ class _PlayerItemState extends State<PlayerItem>
bottom: 0,
child: SlideTransition(
position: _leftOffsetAnimation,
child: IconButton(
icon: Icon(
lockPanel
? Icons.lock_outline
: Icons.lock_open,
color: Colors.white,
child: Column(children: [
const Spacer(),
(lockPanel)
? Container()
: IconButton(
icon: const Icon(
Icons.photo_camera_outlined,
color: Colors.white,
),
onPressed: () {
_handleScreenshot();
},
),
IconButton(
icon: Icon(
lockPanel
? Icons.lock_outline
: Icons.lock_open,
color: Colors.white,
),
onPressed: () {
setState(() {
lockPanel = !lockPanel;
});
},
),
onPressed: () {
setState(() {
lockPanel = !lockPanel;
});
},
),
const Spacer(),
]),
),
),

Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
saver_gallery:
dependency: "direct main"
description:
name: saver_gallery
sha256: bf59475e50b73d666630bed7a5fdb621fed92d637f64e3c61ce81653ec6a833c
url: "https://pub.dev"
source: hosted
version: "4.0.1"
screen_brightness_android:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ dependencies:
flutter_rating_bar: ^4.0.1
scrollview_observer: ^1.22.0
styled_text: ^8.1.0
saver_gallery: ^4.0.0
webview_windows:
git:
url: https://github.com/Predidit/flutter-webview-windows.git
Expand Down

0 comments on commit 773bf27

Please sign in to comment.