Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
fumin65
2024-04-01 22:20:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ff54534f0e969f26b367fa8bd396c348f7612d3d
ff54534f
1 parent
09df0efb
add pause function to macos part
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
13 deletions
macos/Classes/MobileScannerPlugin.swift
macos/Classes/MobileScannerPlugin.swift
View file @
ff54534
...
...
@@ -36,6 +36,14 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
var
analyzing
:
Bool
=
false
var
position
=
AVCaptureDevice
.
Position
.
back
private
var
stopped
:
Bool
{
return
device
==
nil
||
captureSession
==
nil
}
private
var
paused
:
Bool
{
return
stopped
&&
textureId
!=
nil
}
public
static
func
register
(
with
registrar
:
FlutterPluginRegistrar
)
{
let
instance
=
MobileScannerPlugin
(
registrar
.
textures
)
let
method
=
FlutterMethodChannel
(
name
:
...
...
@@ -67,6 +75,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
resetScale
(
call
,
result
)
// case "analyze":
// switchAnalyzeMode(call, result)
case
"pause"
:
pause
(
result
)
case
"stop"
:
stop
(
result
)
case
"updateScanWindow"
:
...
...
@@ -254,7 +264,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
return
}
textureId
=
registry
.
register
(
self
)
textureId
=
textureId
??
registry
.
register
(
self
)
captureSession
=
AVCaptureSession
()
let
argReader
=
MapArgumentReader
(
call
.
arguments
as?
[
String
:
Any
])
...
...
@@ -381,29 +391,48 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
// result(nil)
// }
func
pause
(
_
result
:
FlutterResult
)
{
if
(
paused
||
stopped
)
{
result
(
nil
)
return
}
releaseCamera
()
}
func
stop
(
_
result
:
FlutterResult
)
{
if
(
device
==
nil
||
captureSession
==
nil
)
{
if
(
!
paused
&&
stopped
)
{
result
(
nil
)
return
}
releaseCamera
()
releaseTexture
()
result
(
nil
)
}
private
func
releaseCamera
()
{
guard
let
captureSession
=
captureSession
else
{
return
}
captureSession
!.
stopRunning
()
for
input
in
captureSession
!.
inputs
{
captureSession
!.
removeInput
(
input
)
captureSession
.
stopRunning
()
for
input
in
captureSession
.
inputs
{
captureSession
.
removeInput
(
input
)
}
for
output
in
captureSession
!.
outputs
{
captureSession
!.
removeOutput
(
output
)
for
output
in
captureSession
.
outputs
{
captureSession
.
removeOutput
(
output
)
}
device
.
removeObserver
(
self
,
forKeyPath
:
#
keyPath
(
AVCaptureDevice
.
torchMode
))
registry
.
unregisterTexture
(
textureId
)
// analyzeMode = 0
latestBuffer
=
nil
captureSession
=
nil
self
.
captureSession
=
nil
device
=
nil
textureId
=
nil
}
result
(
nil
)
private
func
releaseTexture
()
{
registry
.
unregisterTexture
(
textureId
)
textureId
=
nil
}
// Observer for torch state
...
...
Please
register
or
login
to post a comment