Closed yeldar-nurpeissov closed 5 years ago
Hi Yeldar, apologies I couldn't get back to you earlier. This feature is definitely useful and I will try implementing this in next couple of days.
I've implemented onDuration callback in v1.07. Please try and let me know if it doesn't work.
Hi Khuram. Thank you for your implementation. But this version broke my application. Player is stopped after some actions (I will write case bellow), and prints error continuously.
E/MediaPlayerNative( 8299): pause called in state 0, mPlayer(0x7c88960c80) E/MediaPlayerNative( 8299): error (-38, 0) E/MediaPlayerNative( 8299): Attempt to call getDuration in wrong state: mPlayer=0x7c88960c80, mCurrentState=0
My app has play next audio button. When clicking the play next button I call dispose()
method before calling play()
method. Sometimes the app stops playing at this moment, sometimes after if I also click pause button.
You do not need to call dispose before playing next media. Calling dispose would kill the underlying platform view and so any actions you perform after that would produce unpredictable behaviour. If you just pass the new URL to play then it should be able to handle that.
Thanks it fixed. But just playing with new URL it does not play new audio, it plays the same audio of previous URL(it does just continue playing).
import 'package:flutter/material.dart';
import 'package:flutter_playout/audio.dart';
import 'package:flutter_playout/player_observer.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with PlayerObserver {
Audio player;
@override
void initState() {
player = Audio();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.play_arrow),
onPressed: () {
player.play(
'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3');
},
),
IconButton(
icon: Icon(Icons.skip_next),
onPressed: () {
player.play(
'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3');
},
)
],
),
),
);
}
}
I also tried with new small project.
This is on android platform.
Try with 1.0.8 and let me know if it works. Also when calling play with new url, you may want to set position to 0 as well otherwise the new playback would start from the position where previous media was.
Hi Khuram, thank you for your fast action to previous issue.
My json model does not contains duration of audio track. And I think, it is redundant work to calculate and save it somewhere for my all tracks.
Can you please add a callback(listener) to audio duration change?
Thank you.