یلدا ادامه داره... ❤️ ۴۰ درصد تخفیف همه دورهها
استفاده از تخفیفهاسلام خسته نباشید
من از این پلاگین استفاده میکنم : https://pub.dev/packages/flutter_sound
وقتی اولین بار روی دکمه پلی میزنم این رور رو میده و یه 2-3 ثانیه برنامه هنگ میکنه و سنگین میشه تا آهنگ پلی بشه.
E/flutter ( 6408): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The getter 'stream' was called on null.
E/flutter ( 6408): Receiver: null
E/flutter ( 6408): Tried calling: stream
E/flutter ( 6408): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
E/flutter ( 6408): #1 FlutterSound.onPlayerStateChanged (package:flutter_sound/flutter_sound.dart:16:68)
E/flutter ( 6408): #2 _ShowProductPageState.seek (package:alimelodi/pages/show_product.dart:107:40)
E/flutter ( 6408): <asynchronous suspension>
E/flutter ( 6408): #3 _ShowProductPageState._setTimer.<anonymous closure> (package:alimelodi/pages/show_product.dart:51:9)
E/flutter ( 6408): #4 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 6408): #5 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 6408): #6 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 6408): #7 _CustomZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:968:26)
E/flutter ( 6408): #8 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 6408): #9 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 6408): #10 _CustomZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:952:26)
E/flutter ( 6408): #11 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
E/flutter ( 6408): #12 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
E/flutter ( 6408): #13 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)
E/flutter ( 6408):
I/Choreographer( 6408): Skipped 81 frames! The application may be doing too much work on its main thread.
این هم اروری هست که موقع بستن صفحه و فراخوانی متد dispose هست
E/flutter ( 6408): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The getter 'currentPosition' was called on null.
E/flutter ( 6408): Receiver: null
E/flutter ( 6408): Tried calling: currentPosition
E/flutter ( 6408): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
E/flutter ( 6408): #1 _ShowProductPageState.seek.<anonymous closure> (package:alimelodi/pages/show_product.dart:108:26)
E/flutter ( 6408): #2 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 6408): #3 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 6408): #4 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 6408): #5 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter ( 6408): #6 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter ( 6408): #7 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
E/flutter ( 6408): #8 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
E/flutter ( 6408): #9 _rootRun (dart:async/zone.dart:1120:38)
E/flutter ( 6408): #10 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 6408): #11 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter ( 6408): #12 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter ( 6408): #13 _rootRun (dart:async/zone.dart:1124:13)
E/flutter ( 6408): #14 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 6408): #15 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter ( 6408): #16 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter ( 6408): #17 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 6408): #18 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter ( 6408):
اینم کد برنامه :
@override
initState() {
super.initState();
flutterSound = new FlutterSound();
_setTimer();
}
_setTimer() {
timer = Timer.periodic(new Duration(seconds: 1), (Timer t) {
if (isPlaying) {
seek();
}
setState(() {
if (duration == 0.0 || position == 0.0) {
seekValue = 0.0;
} else {
seekValue = (100.0 * position) / duration;
}
});
});
}
@override
void dispose() {
timer?.cancel();
if(position!=0){
stop2();
}
super.dispose();
}
Future<void> play(String url) async {
String path = await flutterSound.startPlayer(url);
await flutterSound.setVolume(1.0);
print('startPlayer: $path');
if (isPlaying) {
seek();
}
_playerSubscription = flutterSound.onPlayerStateChanged.listen((e) {
if (e != null) {
duration = e.duration;
}
});
}
Future<void> pause() async {
String result = await flutterSound.pausePlayer();
print('pausePlayer: $result');
}
Future<void> stop2() async {
String result = await flutterSound.stopPlayer();
print('stopPlayer: $result');
}
Future<void> stop() async {
String result = await flutterSound.stopPlayer();
print('stopPlayer: $result');
setState(() {
position = 0;
});
}
Future<void> seek() async {
_playerSubscription = flutterSound.onPlayerStateChanged.listen((p) {
if (isPlaying && p.currentPosition + 200.0 >= p.duration) {
seekToSecond(0);
stop();
setState(() {
isPlaying = false;
});
}
setState(() {
position = p.currentPosition;
});
if (isPlaying) {
setState(() {
duration = p.duration;
});
}
if (position != 0.0) {
setState(() {
isLoadingToPlay = false;
});
}
});
print('D = ${duration.toString()}');
print('P = ${position.toString()}');
}
Future<void> seekToSecond(int milliSecond) async {
await flutterSound.seekToPlayer(milliSecond);
}
ممنون میشم بگین باید چیکار کنم!
@hesammousavi
تشکر
@elyasbeshkani
سلام من هم مشکل شما رو داشتم. من کد های خودم رو به شکل زیر نوشتم درست شد.
if(_flutterSound.audioState==t_AUDIO_STATE.IS_STOPPED){
await _flutterSound.startPlayer(_audio.path).then(
(path){
_playerSubscription=_flutterSound.onPlayerStateChanged.listen((playerState){
if(playerState!=null){
if(_flutterSound.audioState==t_AUDIO_STATE.IS_STOPPED){
setState(() {
_isPlaying=false;
});
_playPauseIconController.reverse();
_playerSubscription.cancel();
_playerSubscription = null;
}
}
});
});
}else{
//_playerSubscription.resume();
_flutterSound.resumePlayer();
}
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟