thyagoluciano / flutter_radio

Radio station streaming example with ExoPlayer and Flutter.
GNU General Public License v3.0
86 stars 41 forks source link

Start audio on "initState" #8

Closed yagoliveira92 closed 5 years ago

yagoliveira92 commented 5 years ago

How can I start audio on initState?

thyagoluciano commented 5 years ago

@override void initState() { super.initState(); audioStart(); }

Future audioStart() async { await FlutterRadio.audioStart(); print('Audio Start OK'); }

yagoliveira92 commented 5 years ago

I see that in the exemple, but don't work. I think: How the audio can be start if I don't pass the streamUrl in parameters?

I try modify the Dart Code like that:

 String streaming = "https://azuracast.tecnocampinfo.com.br/radio/8000/listen.mp3";

  @override
  void initState() {
    super.initState();
    audioStart(streaming);
  }

  Future<void> audioStart(url) async {
    await FlutterRadio.play(url: url);
    print('Audio Start OK');
  }

But I got that error:

E/flutter (20068): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (20068): PlatformException(error, lateinit property radioManager has not been initialized, null)
yagoliveira92 commented 5 years ago

I resolved creating one metod

Future<void> audioOnInit() async {
    await FlutterRadio.play(url: streamUrl);
    print('Audio Start On Init OK');
  }

and calling this metod in initState()

@override
  void initState() {
    super.initState();
    audioStart();
    audioOnInit();
  }

Thanks =D