@@ -63,7 +63,7 @@ class LivePlaybackWithoutBackPressure extends StatefulWidget {
63
63
64
64
class _LivePlaybackWithoutBackPressureState
65
65
extends State <LivePlaybackWithoutBackPressure > {
66
- FlutterSoundPlayer _mPlayer = FlutterSoundPlayer ();
66
+ final FlutterSoundPlayer _mPlayer = FlutterSoundPlayer ();
67
67
bool _mPlayerIsInited = false ;
68
68
double _mSpeed = 100.0 ;
69
69
@@ -72,7 +72,7 @@ class _LivePlaybackWithoutBackPressureState
72
72
super .initState ();
73
73
// Be careful : openAudioSession return a Future.
74
74
// Do not access your FlutterSoundPlayer or FlutterSoundRecorder before the completion of the Future
75
- _mPlayer! .openPlayer ().then ((value) {
75
+ _mPlayer.openPlayer ().then ((value) {
76
76
setState (() {
77
77
_mPlayerIsInited = true ;
78
78
});
@@ -82,7 +82,7 @@ class _LivePlaybackWithoutBackPressureState
82
82
@override
83
83
void dispose () {
84
84
stopPlayer ();
85
- _mPlayer! .closePlayer ();
85
+ _mPlayer.closePlayer ();
86
86
super .dispose ();
87
87
}
88
88
@@ -100,8 +100,8 @@ class _LivePlaybackWithoutBackPressureState
100
100
}
101
101
102
102
void play () async {
103
- assert (_mPlayerIsInited && _mPlayer! .isStopped);
104
- await _mPlayer! .startPlayerFromStream (
103
+ assert (_mPlayerIsInited && _mPlayer.isStopped);
104
+ await _mPlayer.startPlayerFromStream (
105
105
codec: Codec .pcm16,
106
106
numChannels: 1 ,
107
107
sampleRate: tSampleRate,
@@ -110,13 +110,13 @@ class _LivePlaybackWithoutBackPressureState
110
110
setState (() {});
111
111
var data = await getAssetData ('assets/samples/sample.pcm' );
112
112
feedHim (data);
113
- if (_mPlayer != null ) {
113
+ // if (_mPlayer != null) {
114
114
// We must not do stopPlayer() directely //await stopPlayer();
115
- _mPlayer! .foodSink! .add (FoodEvent (() async {
116
- await _mPlayer! .stopPlayer ();
115
+ _mPlayer.foodSink! .add (FoodEvent (() async {
116
+ await _mPlayer.stopPlayer ();
117
117
setState (() {});
118
118
}));
119
- }
119
+ // }
120
120
}
121
121
122
122
// --------------------- (it was very simple, wasn't it ?) -------------------
@@ -127,9 +127,9 @@ class _LivePlaybackWithoutBackPressureState
127
127
}
128
128
129
129
Future <void > stopPlayer () async {
130
- if (_mPlayer != null ) {
131
- await _mPlayer! .stopPlayer ();
132
- }
130
+ // if (_mPlayer != null) {
131
+ await _mPlayer.stopPlayer ();
132
+ // }
133
133
}
134
134
135
135
@@ -148,7 +148,7 @@ class _LivePlaybackWithoutBackPressureState
148
148
if (! _mPlayerIsInited) {
149
149
return null ;
150
150
}
151
- return _mPlayer! .isStopped
151
+ return _mPlayer.isStopped
152
152
? play
153
153
: () {
154
154
stopPlayer ().then ((value) => setState (() {}));
@@ -180,12 +180,12 @@ class _LivePlaybackWithoutBackPressureState
180
180
onPressed: getPlaybackFn (),
181
181
//color: Colors.white,
182
182
//disabledColor: Colors.grey,
183
- child: Text (_mPlayer! .isPlaying ? 'Stop' : 'Play' ),
183
+ child: Text (_mPlayer.isPlaying ? 'Stop' : 'Play' ),
184
184
),
185
185
const SizedBox (
186
186
width: 20 ,
187
187
),
188
- Text (_mPlayer! .isPlaying
188
+ Text (_mPlayer.isPlaying
189
189
? 'Playback in progress'
190
190
: 'Player is stopped' ),
191
191
]),
0 commit comments