Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 21, 2023
1 parent 9bd9c66 commit fa66956
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 35 deletions.
20 changes: 20 additions & 0 deletions package/play/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ add library in first dart file
import 'package:play/play.dart';
```

### Flutter


```dart
import 'package:flutter/material.dart';
import 'package:play/play.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
Play.ensureInitialized();
/// --- your code
/// return runApp(
/// const MaterialApp(home: MainPage()),
///);
}
```

Audio Player
```dart
Expand Down
112 changes: 83 additions & 29 deletions package/play/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import 'package:flutter/foundation.dart';
import "package:universal_io/io.dart";
import 'package:file_picker/file_picker.dart';
import "package:device_frame/device_frame.dart";

import 'package:flutter/material.dart';
import 'package:play/play.dart';
import "package:device_frame/device_frame.dart";

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -165,7 +166,8 @@ class _MainPageState extends State<MainPage> {
children: [
TextButton(
onPressed: () async {
String? dir = await FilePicker.platform.getDirectoryPath();
String? dir =
await FilePicker.platform.getDirectoryPath();
if (dir != null) {
var directory = Directory(dir);
setState(() {
Expand Down Expand Up @@ -241,7 +243,8 @@ class _MainPageState extends State<MainPage> {
left: 0,
right: 0,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 0),
padding: const EdgeInsets.symmetric(
horizontal: 0),
child: Row(
children: [
InkWell(
Expand All @@ -259,10 +262,13 @@ class _MainPageState extends State<MainPage> {
),
InkWell(
onTap: () async {
await media_controller.playOrPause();
await media_controller
.playOrPause();
},
child: Icon(
(media_controller.isPlaying) ? Icons.pause : Icons.play_arrow,
(media_controller.isPlaying)
? Icons.pause
: Icons.play_arrow,
color: Colors.white,
),
),
Expand All @@ -279,15 +285,26 @@ class _MainPageState extends State<MainPage> {
),
Expanded(
child: StreamBuilder(
stream: media_controller.streamDurationPosition(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
stream: media_controller
.streamDurationPosition(),
builder: (BuildContext context,
AsyncSnapshot snapshot) {
return Slider(
min: 0,
max: media_controller.getDurationMax().inMicroseconds.toDouble(),
value: media_controller.getDurationPosition().inMicroseconds.toDouble(),
onChanged: (double value) async {

await media_controller.seek(Duration(microseconds: value.toInt()));
max: media_controller
.getDurationMax()
.inMicroseconds
.toDouble(),
value: media_controller
.getDurationPosition()
.inMicroseconds
.toDouble(),
onChanged:
(double value) async {
await media_controller.seek(
Duration(
microseconds:
value.toInt()));
setState(() {});
},
);
Expand Down Expand Up @@ -319,14 +336,19 @@ class _MainPageState extends State<MainPage> {
itemBuilder: (context, i) {
return Video(
key: Key("video :${i}"),
mediaData: MediaData.file(file: File(files[i].path)),
mediaData:
MediaData.file(file: File(files[i].path)),
id: i,
onProcces: (context) {
return const Text(
"Thumbnail",
);
},
builder: (BuildContext context, Widget child, Video video, VideoState videoState, MediaController mediaController) {
builder: (BuildContext context,
Widget child,
Video video,
VideoState videoState,
MediaController mediaController) {
if (index != i) {
videoState.mediaController.pause();
} else {
Expand All @@ -347,7 +369,8 @@ class _MainPageState extends State<MainPage> {
children: [
Center(
child: AspectRatio(
aspectRatio: videoState.mediaController.aspectRatio,
aspectRatio: videoState
.mediaController.aspectRatio,
child: child,
),
),
Expand All @@ -356,13 +379,17 @@ class _MainPageState extends State<MainPage> {
left: 0,
right: 0,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 0),
padding:
const EdgeInsets.symmetric(
horizontal: 0),
child: Row(
children: [
InkWell(
onTap: () {
videoState.mediaController.pause();
pageController.jumpToPage(i - 1);
videoState.mediaController
.pause();
pageController
.jumpToPage(i - 1);
},
child: const RotatedBox(
quarterTurns: 2,
Expand All @@ -374,21 +401,29 @@ class _MainPageState extends State<MainPage> {
),
InkWell(
onTap: () async {
await videoState.mediaController.playOrPause();
await videoState
.mediaController
.playOrPause();
setState(() {
isPlay = !videoState.mediaController.isPlaying;
isPlay = !videoState
.mediaController
.isPlaying;
});
},
child: Icon(
(isPlay) ? Icons.pause : Icons.play_arrow,
(isPlay)
? Icons.pause
: Icons.play_arrow,
color: Colors.white,
),
),
InkWell(
onTap: () {
videoState.mediaController.pause();
videoState.mediaController
.pause();

pageController.jumpToPage(i + 1);
pageController
.jumpToPage(i + 1);
},
child: const Icon(
Icons.skip_next,
Expand All @@ -397,15 +432,34 @@ class _MainPageState extends State<MainPage> {
),
Expanded(
child: StreamBuilder(
stream: videoState.mediaController.streamDurationPosition(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
stream: videoState
.mediaController
.streamDurationPosition(),
builder:
(BuildContext context,
AsyncSnapshot
snapshot) {
return Slider(
min: 0,
max: videoState.mediaController.getDurationMax().inMilliseconds.toDouble(),
value: videoState.mediaController.getDurationPosition().inMilliseconds.toDouble(),
onChanged: (double value) {
max: videoState
.mediaController
.getDurationMax()
.inMilliseconds
.toDouble(),
value: videoState
.mediaController
.getDurationPosition()
.inMilliseconds
.toDouble(),
onChanged:
(double value) {
setState(() {
videoState.mediaController.seek(Duration(milliseconds: value.toInt()));
videoState
.mediaController
.seek(Duration(
milliseconds:
value
.toInt()));
});
},
);
Expand Down
2 changes: 2 additions & 0 deletions package/play/lib/media_kit/media_kit_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class PlayerState {
Duration get duration {
return Duration();
}

Duration get position {
return Duration();
}
Expand All @@ -50,6 +51,7 @@ class PlayerStreams {
Duration get duration {
return Duration();
}

Stream<Duration> get position {
return Future(() => Duration()).asStream();
}
Expand Down
4 changes: 2 additions & 2 deletions package/play/lib/media_kit_video/media_kit_video.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// export "media_kit_video_web.dart";

export "media_kit_video_app.dart" if (dart.library.html) "media_kit_video_web.dart";

export "media_kit_video_app.dart"
if (dart.library.html) "media_kit_video_web.dart";
2 changes: 1 addition & 1 deletion package/play/lib/play.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export "src/media.dart";
export "widget/media.dart";
export "widget/video.dart";

export "play_core.dart";
export "play_core.dart";
8 changes: 5 additions & 3 deletions package/play/lib/src/media.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension MediaControllerExtensions on MediaController {
}
if (isDesktop) {
return desktop_player.streams.position.last;
} else if (isMobile) {
} else if (isMobile) {
return (await mobilePlayer.position) ?? Duration();
}
return Duration();
Expand All @@ -52,7 +52,7 @@ extension MediaControllerExtensions on MediaController {
return Stream.value(Duration(milliseconds: 1));
}
if (isDesktop) {
return desktop_player.streams.position;
return desktop_player.streams.position;
// return desktop_player.positionStream;
} else if (isMobile) {
return mobilePlayer.position.asStream();
Expand Down Expand Up @@ -81,7 +81,9 @@ extension MediaControllerExtensions on MediaController {
if (isDesktop) {
await desktop_player.playOrPause();
} else {
(mobilePlayer.value.isPlaying == true) ? await mobilePlayer.pause() : await mobilePlayer.play();
(mobilePlayer.value.isPlaying == true)
? await mobilePlayer.pause()
: await mobilePlayer.play();
}
}

Expand Down

0 comments on commit fa66956

Please sign in to comment.