[✓] Flutter (Channel master, v1.13.1-pre.59, on Mac OS X 10.14.6 18G2022, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0-rc2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
[✓] Android Studio (version 3.5)
[✓] IntelliJ IDEA Community Edition (version 2018.3.5)
[✓] VS Code (version 1.40.2)
[✓] Connected device (2 available)
IOS
resume the sound
crash with this exception
IOS Simulator : failed
Android Real Device : worked
I am using the plugin from provider and ValueNotifier
I have also cached the music using cache manager and used startPlayerFromBuffer to play the local version of the song
@Larpoux Could you kindly look into this issue?
Yes, Hyo. I am looking to that.
Hi @frediustcDev,
I cannot reproduce your crash with our example app. The pause function seems to work correctly, both with StartPlayer and StartPlayerFromBuffer on the iOS simulator.
Could you give more informations (the functions calling stack would be very useful, if you get it).
Note : The example app tests the variable flutterSound.audioState before calling flutterSound.pausePlayer () or flutterSound.resumePlayer () so that those functions are never called during an illegal state. I am going to verify now, that there is no crash if the caller uses those functions illegally.
Some modifications have been done recently in this area so that an exception is thrown if the caller calls those function in a bad state. Please, could you verify that your problem still occurs with flutter_sound 2.0.3 ?
I found a little bug when the native plugin returns an error. We tried to return this error as the result String. I changed that, to throw an exception to the caller.
As mentioned I am using provider so this is the file. Consider to check the playpause method. I don't know if it is my code but I have discovered that my whole app stack when I press play till the music has loaded. If it is about the code can you please give me a better approach. I also don't know about swift or Java. So if I can help you in some way in the Dart code to improve the plug-in, I will be happy to do so. Thx guys
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
enum REPEAT_MODE { REPEAT_ONE, REPEAT_ALL, NONE, SHUFFLE }
class AudioPlayerProvider extends ChangeNotifier {
//static public variable
final FlutterSound audioPlayer = FlutterSound();
final DefaultCacheManager cache = DefaultCacheManager();
//static private variable
bool _isPlaying = false;
bool _isLoading = false;
LazyCacheMap _music;
List _playlist = [];
double _maxDuration = 1;
double _currentDuration = 0;
REPEAT_MODE _repeatMode = REPEAT_MODE.NONE;
_subscribe() {
audioPlayer.onPlayerStateChanged.listen((state) {
if (state != null) {
if (_maxDuration != state.duration) maxDuration(state.duration);
if (_currentDuration != state.currentPosition)
currentDuration(state.currentPosition);
//when the music has stopped play
if (_currentDuration >= _maxDuration) {
if (repeatMode() == REPEAT_MODE.NONE) {
isPlaying(false);
} else {
switch (repeatMode()) {
case REPEAT_MODE.REPEAT_ALL:
skipToNext();
break;
case REPEAT_MODE.REPEAT_ONE:
play(music());
break;
case REPEAT_MODE.SHUFFLE:
print('shuffle');
int index = Random().nextInt(playlist().length);
LazyCacheMap music = playlist()[index];
play(music);
break;
default:
break;
}
}
}
}
});
}
//main methods setter / getter
music([LazyCacheMap music]) {
if (music != null) {
_music = music;
notifyListeners();
}
return _music;
}
List playlist([List playlist]) {
if (playlist != null) {
_playlist = playlist;
notifyListeners();
}
return _playlist;
}
REPEAT_MODE repeatMode([REPEAT_MODE repeatMode]) {
if (repeatMode != null) {
if (repeatMode == _repeatMode) {
_repeatMode = null;
} else {
_repeatMode = repeatMode;
}
notifyListeners();
}
return _repeatMode;
}
bool isPlaying([bool isPlaying]) {
if (isPlaying != null) {
_isPlaying = isPlaying;
notifyListeners();
}
return _isPlaying;
}
bool isLoading([bool isLoading]) {
if (isLoading != null) {
_isLoading = isLoading;
notifyListeners();
}
return _isLoading;
}
//main method getter
double maxDuration([double duration]) {
if (duration != null) {
_maxDuration = duration;
notifyListeners();
}
return _maxDuration;
}
double currentDuration([double duration]) {
if (duration != null) {
_currentDuration = duration;
notifyListeners();
}
return _currentDuration;
}
getMusic() => _music;
getPlaylist() => _playlist;
//main action's method
play(LazyCacheMap newMusic, [List newPlaylist]) async {
// cache.emptyCache();
if (newMusic == null) return;
if (newMusic == _music &&
audioPlayer.audioState != t_AUDIO_STATE.IS_STOPPED) {
return;
}
music(newMusic);
if (playlist != null) playlist(newPlaylist);
try {
isLoading(true);
String url = newMusic['url'];
FileInfo info = await cache.getFileFromCache(url);
if (audioPlayer.audioState != t_AUDIO_STATE.IS_STOPPED) {
await audioPlayer.stopPlayer();
}
if (info != null) {
await audioPlayer.startPlayerFromBuffer(
info.file.readAsBytesSync(),
);
} else {
await audioPlayer.startPlayer(url);
}
isPlaying(true);
isLoading(false);
_subscribe();
notifyListeners();
await cache.getSingleFile(url);
} catch (e) {
isPlaying(false);
print(e.message);
}
}
resumePause() async {
try {
switch (audioPlayer.audioState) {
case t_AUDIO_STATE.IS_PLAYING:
isPlaying(false);
return await audioPlayer.pausePlayer();
case t_AUDIO_STATE.IS_PAUSED:
isPlaying(true);
return await audioPlayer.resumePlayer();
case t_AUDIO_STATE.IS_STOPPED:
return await play(_music, _playlist);
default:
break;
}
notifyListeners();
} catch (e) {
isPlaying(false);
print(e);
}
}
skipToPrevious() async {
final int _currentIndex = _playlist.indexOf(_music);
int _nextIndex =
_currentIndex <= 0 ? _playlist.length - 1 : _currentIndex - 1;
final music = _playlist[_nextIndex];
notifyListeners();
play(music);
}
skipToNext() async {
final int _currentIndex = _playlist.indexOf(_music);
int _nextIndex =
_currentIndex >= _playlist.length - 1 ? 0 : _currentIndex + 1;
final music = _playlist[_nextIndex];
notifyListeners();
play(music);
}
seek(int duration) {
audioPlayer.seekToPlayer(duration);
notifyListeners();
}
}
Bonjour Fredius Tout Court :-D.
I do not really know what to do with your bug report.
I actually have no clue : you say that there is a crash but you do not say what kind of crash ?
Your bug report is :
Expected behavior
resume the sound
Actual behavior
crash with this exception
Tested environment (Emulator? Real Device?)
IOS Simulator : failed
Android Real Device : worked
but the exception that you get is missing. Just crash with this exception without nothing after.
Also, I would like to have all your logs. Do you use Android Studio ? Visual Code ? Flutter command line ?
PS: I did not know flutter provider, but I rapidly looked on pub.dev and it seems very interesting. I will definitely look to it when I will have some time.
Désolé, je ne sais vraiment pas par quel bout prendre ton/votre bug.
Moi c'est Larpoux tout court :-D
hi @Larpoux, I have tried the app today and the resume / pause. sudenly work. i don't know what was the problem. if the crash come again I will show you the exception
Glad to hear that your problem is fixed.
Do not forget to post your total logs if you must redo another bug report.
Hyo ? Is this my responsibility to close this PR ? Or is it you ?
On 28 Jan 2020 at 11:34 +0100, Fredius Tout Court notifications@github.com, wrote:
hi @Larpoux, I have tried the app today and the resume / pause. sudenly work. i don't know what was the problem. if the crash come again I will show you the exception
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
OK I will do so
Most helpful comment
Yes, Hyo. I am looking to that.