Skip to content

Commit

Permalink
recoding app version 2: done rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunhThanhDe committed Sep 12, 2022
1 parent ec3facb commit 3e0d84a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 32 deletions.
5 changes: 3 additions & 2 deletions lib/camera_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ class _CameraPageState extends State<CameraPage> {
}
},
onVideoRecorded: (value) {
File file = File(value.path);
final path = value.path;
if (path.contains('.mp4')) {
final route = MaterialPageRoute(
fullscreenDialog: false,
builder: (_) => VideoPage(filePath: path),
builder: (_) => VideoPage(filePath: path, file: file),
);
Navigator.push(context, route);
}

///Show video preview .mp4
},
);
// return Container();
}
}

70 changes: 42 additions & 28 deletions lib/video_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:http/http.dart' as http;

class VideoPage extends StatefulWidget {
final String filePath;
final File file;

const VideoPage({Key? key, required this.filePath}) : super(key: key);
const VideoPage({Key? key, required this.filePath, required this.file})
: super(key: key);

@override
_VideoPageState createState() => _VideoPageState();
Expand All @@ -23,7 +26,6 @@ class _VideoPageState extends State<VideoPage> {
_videoPlayerController = VideoPlayerController.file(File(widget.filePath));
_initVideoPlayer = _videoPlayerController.initialize();
_videoPlayerController.setLooping(true);
_videoPlayerController.play();
}

@override
Expand All @@ -32,12 +34,6 @@ class _VideoPageState extends State<VideoPage> {
super.dispose();
}

// Future _initVideoPlayer() async {
// _videoPlayerController = VideoPlayerController.file(File(widget.filePath));
// await _videoPlayerController.initialize();
// await _videoPlayerController.setLooping(true);
// await _videoPlayerController.play();
// }

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -67,27 +63,45 @@ class _VideoPageState extends State<VideoPage> {
}
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// Wrap the play or pause in a call to `setState`. This ensures the
// correct icon is shown.
setState(() {
// If the video is playing, pause it.
if (_videoPlayerController.value.isPlaying) {
_videoPlayerController.pause();
} else {
// If the video is paused, play it.
_videoPlayerController.play();
}
});
},
// Display the correct icon depending on the state of the player.
child: Icon(
_videoPlayerController.value.isPlaying
? Icons.pause
: Icons.play_arrow,
),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FloatingActionButton(
onPressed: () {
// Wrap the play or pause in a call to `setState`. This ensures the
// correct icon is shown.
setState(() {
// If the video is playing, pause it.
if (_videoPlayerController.value.isPlaying) {
_videoPlayerController.pause();
} else {
// If the video is paused, play it.
_videoPlayerController.play();
}
});
},
// Display the correct icon depending on the state of the player.
child: Icon(
_videoPlayerController.value.isPlaying
? Icons.pause
: Icons.play_arrow,
),
),
FloatingActionButton(onPressed: () => _uploadFile(widget.file))
],
),
);
}

void _uploadFile(File file) async {
var request = http.MultipartRequest(
'POST', Uri.parse('http://192.168.1.61:5000/uploadFile'));
request.files.add(await http.MultipartFile.fromPath('file', file.path));
var response = await request.send();
if(response.statusCode == 200 ){
print('ok');
}else{
print('no');
};
}
}
21 changes: 21 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.0"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.5"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.1"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -245,6 +259,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.12"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
vector_math:
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 @@ -38,6 +38,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
http: ^0.13.5

dev_dependencies:
flutter_test:
Expand Down
4 changes: 2 additions & 2 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:camera_app/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:recording_app/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpWidget(MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand Down

0 comments on commit 3e0d84a

Please sign in to comment.