Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OnePoem
/
OnePoem-App
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Reason Pun
2022-01-25 11:11:31 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4c84b1aa609772c80498a6f0b6285b11ea64608d
4c84b1aa
1 parent
0d94adfa
清理了视频录制页面按钮(可通过此次提交恢复)
升级了插件版本
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
157 additions
and
492 deletions
lib/poem/page/poem_record_video.dart
lib/recorder/video/preview_screen.dart
pubspec.lock
lib/poem/page/poem_record_video.dart
View file @
4c84b1a
...
...
@@ -23,20 +23,10 @@ class _PoemRecordVideoPageState extends State<PoemRecordVideoPage>
File
?
_imageFile
;
File
?
_videoFile
;
// Initial values
final
bool
_isVideoCameraSelected
=
true
;
bool
_isCameraInitialized
=
false
;
bool
_isRearCameraSelected
=
true
;
bool
_isVideoCameraSelected
=
false
;
bool
_isRecordingInProgress
=
false
;
double
_minAvailableExposureOffset
=
0.0
;
double
_maxAvailableExposureOffset
=
0.0
;
double
_minAvailableZoom
=
1.0
;
double
_maxAvailableZoom
=
1.0
;
// Current values
double
_currentZoomLevel
=
1.0
;
double
_currentExposureOffset
=
0.0
;
FlashMode
?
_currentFlashMode
;
List
<
File
>
allFileList
=
[];
...
...
@@ -193,11 +183,6 @@ class _PoemRecordVideoPageState extends State<PoemRecordVideoPage>
}
}
void
resetCameraValues
()
async
{
_currentZoomLevel
=
1.0
;
_currentExposureOffset
=
0.0
;
}
void
onNewCameraSelected
(
CameraDescription
cameraDescription
)
async
{
final
previousCameraController
=
controller
;
...
...
@@ -209,8 +194,6 @@ class _PoemRecordVideoPageState extends State<PoemRecordVideoPage>
await
previousCameraController
?.
dispose
();
resetCameraValues
();
if
(
mounted
)
{
setState
(()
{
controller
=
cameraController
;
...
...
@@ -224,22 +207,6 @@ class _PoemRecordVideoPageState extends State<PoemRecordVideoPage>
try
{
await
cameraController
.
initialize
();
await
Future
.
wait
([
cameraController
.
getMinExposureOffset
()
.
then
((
value
)
=>
_minAvailableExposureOffset
=
value
),
cameraController
.
getMaxExposureOffset
()
.
then
((
value
)
=>
_maxAvailableExposureOffset
=
value
),
cameraController
.
getMaxZoomLevel
()
.
then
((
value
)
=>
_maxAvailableZoom
=
value
),
cameraController
.
getMinZoomLevel
()
.
then
((
value
)
=>
_minAvailableZoom
=
value
),
]);
_currentFlashMode
=
controller
!.
value
.
flashMode
;
}
on
CameraException
catch
(
e
)
{
// print('Error initializing camera: $e');
}
...
...
@@ -280,484 +247,182 @@ class _PoemRecordVideoPageState extends State<PoemRecordVideoPage>
child:
Scaffold
(
backgroundColor:
Colors
.
black
,
body:
_isCameraInitialized
?
Column
(
?
Stack
(
children:
[
AspectRatio
(
aspectRatio:
1
/
controller
!.
value
.
aspectRatio
,
child:
Stack
(
controller
!.
buildPreview
(),
Padding
(
padding:
const
EdgeInsets
.
fromLTRB
(
16.0
,
8.0
,
16.0
,
8.0
,
),
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
end
,
children:
[
controller
!.
buildPreview
(),
Padding
(
padding:
const
EdgeInsets
.
fromLTRB
(
16.0
,
8.0
,
16.0
,
8.0
,
),
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
end
,
children:
[
Align
(
alignment:
Alignment
.
topRight
,
child:
Container
(
decoration:
BoxDecoration
(
color:
Colors
.
black87
,
borderRadius:
BorderRadius
.
circular
(
10.0
),
),
child:
Padding
(
padding:
const
EdgeInsets
.
only
(
left:
8.0
,
right:
8.0
,
),
child:
DropdownButton
<
ResolutionPreset
>(
dropdownColor:
Colors
.
black87
,
underline:
Container
(),
value:
currentResolutionPreset
,
items:
[
for
(
ResolutionPreset
preset
in
resolutionPresets
)
DropdownMenuItem
(
child:
Text
(
preset
.
toString
()
.
split
(
'.'
)[
1
]
.
toUpperCase
(),
style:
const
TextStyle
(
color:
Colors
.
white
),
),
value:
preset
,
)
],
onChanged:
(
value
)
{
setState
(()
{
currentResolutionPreset
=
value
!;
_isCameraInitialized
=
false
;
});
onNewCameraSelected
(
controller
!.
description
);
},
hint:
const
Text
(
"Select item"
),
),
),
),
),
// Spacer(),
Padding
(
padding:
const
EdgeInsets
.
only
(
right:
8.0
,
top:
16.0
),
child:
Container
(
decoration:
BoxDecoration
(
color:
Colors
.
white
,
borderRadius:
BorderRadius
.
circular
(
10.0
),
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
_currentExposureOffset
.
toStringAsFixed
(
1
)
+
'x'
,
style:
const
TextStyle
(
color:
Colors
.
black
),
),
),
),
),
Expanded
(
child:
RotatedBox
(
quarterTurns:
3
,
child:
SizedBox
(
height:
30
,
child:
Slider
(
value:
_currentExposureOffset
,
min:
_minAvailableExposureOffset
,
max:
_maxAvailableExposureOffset
,
activeColor:
Colors
.
white
,
inactiveColor:
Colors
.
white30
,
onChanged:
(
value
)
async
{
setState
(()
{
_currentExposureOffset
=
value
;
});
await
controller
!
.
setExposureOffset
(
value
);
},
),
),
),
),
Row
(
// Spacer(),
const
Spacer
(
flex:
1
,
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
[
InkWell
(
onTap:
_isRecordingInProgress
?
()
async
{
if
(
controller
!.
value
.
isRecordingPaused
)
{
await
resumeVideoRecording
();
}
else
{
await
pauseVideoRecording
();
}
}
:
()
{
setState
(()
{
_isCameraInitialized
=
false
;
});
onNewCameraSelected
(
cameras
![
_isRearCameraSelected
?
1
:
0
]);
setState
(()
{
_isRearCameraSelected
=
!
_isRearCameraSelected
;
});
},
child:
Stack
(
alignment:
Alignment
.
center
,
children:
[
Expanded
(
child:
Slider
(
value:
_currentZoomLevel
,
min:
_minAvailableZoom
,
max:
_maxAvailableZoom
,
activeColor:
Colors
.
white
,
inactiveColor:
Colors
.
white30
,
onChanged:
(
value
)
async
{
setState
(()
{
_currentZoomLevel
=
value
;
});
await
controller
!.
setZoomLevel
(
value
);
},
),
const
Icon
(
Icons
.
circle
,
color:
Colors
.
black38
,
size:
60
,
),
Padding
(
padding:
const
EdgeInsets
.
only
(
right:
8.0
),
child:
Container
(
decoration:
BoxDecoration
(
color:
Colors
.
black87
,
borderRadius:
BorderRadius
.
circular
(
10.0
),
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
_currentZoomLevel
.
toStringAsFixed
(
1
)
+
'x'
,
style:
const
TextStyle
(
color:
Colors
.
white
),
_isRecordingInProgress
?
controller
!.
value
.
isRecordingPaused
?
const
Icon
(
Icons
.
play_arrow
,
color:
Colors
.
white
,
size:
30
,
)
:
const
Icon
(
Icons
.
pause
,
color:
Colors
.
white
,
size:
30
,
)
:
Icon
(
_isRearCameraSelected
?
Icons
.
camera_front
:
Icons
.
camera_rear
,
color:
Colors
.
white
,
size:
30
,
),
),
),
),
],
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
),
InkWell
(
onTap:
()
async
{
if
(
_isRecordingInProgress
)
{
XFile
?
rawVideo
=
await
stopVideoRecording
();
File
videoFile
=
File
(
rawVideo
!.
path
);
int
currentUnix
=
DateTime
.
now
().
millisecondsSinceEpoch
;
final
directory
=
await
getApplicationDocumentsDirectory
();
String
fileFormat
=
videoFile
.
path
.
split
(
'.'
).
last
;
_videoFile
=
await
videoFile
.
copy
(
'
${directory.path}
/
$currentUnix
.
$fileFormat
'
,
);
_startVideoPlayer
();
}
else
{
await
startVideoRecording
();
}
},
child:
Stack
(
alignment:
Alignment
.
center
,
children:
[
InkWell
(
onTap:
_isRecordingInProgress
?
()
async
{
if
(
controller
!
.
value
.
isRecordingPaused
)
{
await
resumeVideoRecording
();
}
else
{
await
pauseVideoRecording
();
}
}
:
()
{
setState
(()
{
_isCameraInitialized
=
false
;
});
onNewCameraSelected
(
cameras
![
_isRearCameraSelected
?
1
:
0
]);
setState
(()
{
_isRearCameraSelected
=
!
_isRearCameraSelected
;
});
},
child:
Stack
(
alignment:
Alignment
.
center
,
children:
[
const
Icon
(
Icons
.
circle
,
color:
Colors
.
black38
,
size:
60
,
),
_isRecordingInProgress
?
controller
!
.
value
.
isRecordingPaused
?
const
Icon
(
Icons
.
play_arrow
,
color:
Colors
.
white
,
size:
30
,
)
:
const
Icon
(
Icons
.
pause
,
color:
Colors
.
white
,
size:
30
,
)
:
Icon
(
_isRearCameraSelected
?
Icons
.
camera_front
:
Icons
.
camera_rear
,
color:
Colors
.
white
,
size:
30
,
),
],
),
Icon
(
Icons
.
circle
,
color:
_isVideoCameraSelected
?
Colors
.
white
:
Colors
.
white38
,
size:
80
,
),
InkWell
(
onTap:
_isVideoCameraSelected
?
()
async
{
if
(
_isRecordingInProgress
)
{
XFile
?
rawVideo
=
await
stopVideoRecording
();
File
videoFile
=
File
(
rawVideo
!.
path
);
int
currentUnix
=
DateTime
.
now
()
.
millisecondsSinceEpoch
;
final
directory
=
await
getApplicationDocumentsDirectory
();
String
fileFormat
=
videoFile
.
path
.
split
(
'.'
)
.
last
;
_videoFile
=
await
videoFile
.
copy
(
'
${directory.path}
/
$currentUnix
.
$fileFormat
'
,
);
_startVideoPlayer
();
}
else
{
await
startVideoRecording
();
}
}
:
()
async
{
XFile
?
rawImage
=
await
takePicture
();
File
imageFile
=
File
(
rawImage
!.
path
);
int
currentUnix
=
DateTime
.
now
()
.
millisecondsSinceEpoch
;
final
directory
=
await
getApplicationDocumentsDirectory
();
String
fileFormat
=
imageFile
.
path
.
split
(
'.'
).
last
;
await
imageFile
.
copy
(
'
${directory.path}
/
$currentUnix
.
$fileFormat
'
,
);
refreshAlreadyCapturedImages
();
},
child:
Stack
(
alignment:
Alignment
.
center
,
children:
[
Icon
(
Icons
.
circle
,
color:
_isVideoCameraSelected
?
Colors
.
white
:
Colors
.
white38
,
size:
80
,
),
Icon
(
Icons
.
circle
,
color:
_isVideoCameraSelected
?
Colors
.
red
:
Colors
.
white
,
size:
65
,
),
_isVideoCameraSelected
&&
_isRecordingInProgress
?
const
Icon
(
Icons
.
stop_rounded
,
color:
Colors
.
white
,
size:
32
,
)
:
Container
(),
],
),
Icon
(
Icons
.
circle
,
color:
_isVideoCameraSelected
?
Colors
.
red
:
Colors
.
white
,
size:
65
,
),
InkWell
(
onTap:
_imageFile
!=
null
||
_videoFile
!=
null
?
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
PreviewScreen
(
imageFile:
_imageFile
!,
fileList:
allFileList
,
),
),
);
}
:
null
,
child:
Container
(
width:
60
,
height:
60
,
decoration:
BoxDecoration
(
color:
Colors
.
black
,
borderRadius:
BorderRadius
.
circular
(
10.0
),
border:
Border
.
all
(
_isVideoCameraSelected
&&
_isRecordingInProgress
?
const
Icon
(
Icons
.
stop_rounded
,
color:
Colors
.
white
,
width:
2
,
),
image:
_imageFile
!=
null
?
DecorationImage
(
image:
FileImage
(
_imageFile
!),
fit:
BoxFit
.
cover
,
)
:
null
,
),
child:
videoController
!=
null
&&
videoController
!
.
value
.
isInitialized
?
ClipRRect
(
borderRadius:
BorderRadius
.
circular
(
8.0
),
child:
AspectRatio
(
aspectRatio:
videoController
!
.
value
.
aspectRatio
,
child:
VideoPlayer
(
videoController
!),
),
)
:
Container
(),
),
),
size:
32
,
)
:
Container
(),
],
),
],
),
),
],
),
),
Expanded
(
child:
SingleChildScrollView
(
physics:
const
BouncingScrollPhysics
(),
child:
Column
(
children:
[
Padding
(
padding:
const
EdgeInsets
.
only
(
top:
8.0
),
child:
Row
(
children:
[
Expanded
(
child:
Padding
(
padding:
const
EdgeInsets
.
only
(
left:
8.0
,
right:
4.0
,
),
child:
TextButton
(
onPressed:
_isRecordingInProgress
?
null
:
()
{
if
(
_isVideoCameraSelected
)
{
setState
(()
{
_isVideoCameraSelected
=
false
;
});
}
},
style:
TextButton
.
styleFrom
(
primary:
_isVideoCameraSelected
?
Colors
.
black54
:
Colors
.
black
,
backgroundColor:
_isVideoCameraSelected
?
Colors
.
white30
:
Colors
.
white
,
),
child:
const
Text
(
'IMAGE'
),
),
),
),
Expanded
(
child:
Padding
(
padding:
const
EdgeInsets
.
only
(
left:
4.0
,
right:
8.0
),
child:
TextButton
(
onPressed:
()
{
if
(!
_isVideoCameraSelected
)
{
setState
(()
{
_isVideoCameraSelected
=
true
;
});
}
},
style:
TextButton
.
styleFrom
(
primary:
_isVideoCameraSelected
?
Colors
.
black
:
Colors
.
black54
,
backgroundColor:
_isVideoCameraSelected
?
Colors
.
white
:
Colors
.
white30
,
),
child:
const
Text
(
'VIDEO'
),
),
),
),
],
),
),
Padding
(
padding:
const
EdgeInsets
.
fromLTRB
(
16.0
,
8.0
,
16.0
,
8.0
),
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
[
InkWell
(
onTap:
()
async
{
setState
(()
{
_currentFlashMode
=
FlashMode
.
off
;
});
await
controller
!.
setFlashMode
(
FlashMode
.
off
,
);
},
child:
Icon
(
Icons
.
flash_off
,
color:
_currentFlashMode
==
FlashMode
.
off
?
Colors
.
amber
:
Colors
.
white
,
),
),
InkWell
(
onTap:
()
async
{
setState
(()
{
_currentFlashMode
=
FlashMode
.
auto
;
});
await
controller
!.
setFlashMode
(
FlashMode
.
auto
,
);
},
child:
Icon
(
Icons
.
flash_auto
,
color:
_currentFlashMode
==
FlashMode
.
auto
?
Colors
.
amber
:
Colors
.
white
,
),
),
InkWell
(
onTap:
()
async
{
setState
(()
{
_currentFlashMode
=
FlashMode
.
always
;
});
await
controller
!.
setFlashMode
(
FlashMode
.
always
,
);
},
child:
Icon
(
Icons
.
flash_on
,
color:
_currentFlashMode
==
FlashMode
.
always
?
Colors
.
amber
:
Colors
.
white
,
),
),
InkWell
(
onTap:
()
async
{
setState
(()
{
_currentFlashMode
=
FlashMode
.
torch
;
});
await
controller
!.
setFlashMode
(
FlashMode
.
torch
,
);
},
child:
Icon
(
Icons
.
highlight
,
color:
_currentFlashMode
==
FlashMode
.
torch
?
Colors
.
amber
:
Colors
.
white
,
InkWell
(
onTap:
_imageFile
!=
null
||
_videoFile
!=
null
?
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
PreviewScreen
(
imageFile:
_imageFile
!,
fileList:
allFileList
,
),
),
);
}
:
null
,
child:
Container
(
width:
60
,
height:
60
,
decoration:
BoxDecoration
(
color:
Colors
.
black
,
borderRadius:
BorderRadius
.
circular
(
10.0
),
border:
Border
.
all
(
color:
Colors
.
white
,
width:
2
,
),
image:
_imageFile
!=
null
?
DecorationImage
(
image:
FileImage
(
_imageFile
!),
fit:
BoxFit
.
cover
,
)
:
null
,
),
],
child:
videoController
!=
null
&&
videoController
!.
value
.
isInitialized
?
ClipRRect
(
borderRadius:
BorderRadius
.
circular
(
8.0
),
child:
AspectRatio
(
aspectRatio:
videoController
!
.
value
.
aspectRatio
,
child:
VideoPlayer
(
videoController
!),
),
)
:
Container
(),
),
),
)
]
,
)
,
],
)
,
]
,
),
),
],
)
:
const
Center
(
child:
Text
(
'
LOADING
'
,
'
开启摄像头..
'
,
style:
TextStyle
(
color:
Colors
.
white
),
),
),
...
...
lib/recorder/video/preview_screen.dart
View file @
4c84b1a
...
...
@@ -32,7 +32,7 @@ class PreviewScreen extends StatelessWidget {
),
);
},
child:
Text
(
'Go to all captures
'
),
child:
const
Text
(
'打开全部视频
'
),
style:
TextButton
.
styleFrom
(
primary:
Colors
.
black
,
backgroundColor:
Colors
.
white
,
...
...
pubspec.lock
View file @
4c84b1a
...
...
@@ -1118,7 +1118,7 @@ packages:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.
2
"
version: "2.0.
3
"
url_launcher_platform_interface:
dependency: transitive
description:
...
...
@@ -1181,7 +1181,7 @@ packages:
name: video_player
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1
3
"
version: "2.2.1
5
"
video_player_platform_interface:
dependency: transitive
description:
...
...
Please
register
or
login
to post a comment