3

I am working on radio application where I want to play live stream radio. I have an url using which i will stream the radio and play. How can I play online streaming using this url? Here is my steaming url:

"streams" : -[
-{
"stream" : http://media.powerfm.se:80/high,
"bitrate" : 160,
"content_type" : ?,
"status" : 1,
"listeners" : 0
},
-{
"stream" : fffff,
"bitrate" : 0,
"content_type" : ?,
"status" : 0,
"listeners" : 0
 }
Jonas
  • 121,568
  • 97
  • 310
  • 388
Ammy Kang
  • 11,283
  • 21
  • 46
  • 68

3 Answers3

2

I know I am a little late to this but take a look at Fluttery Audio. A few pieces of advice that I found along the way,

  1. Android devices are not all alike, some of them will work with aac steams others will not.
  2. For ios devices you need to add this chunk of code to your .plist file if it is not a https stream.
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
  1. Android can play audio in the background iOS cannot until changes are made to the library.
Nandan Acharya
  • 900
  • 2
  • 12
  • 24
Chris Long
  • 46
  • 4
1

From what I understand, Flutter doesn't handle this use case, and you'll have to handle audio streaming in native code through plugins for your desired platform.

This seems to be a popular plugin that handles audio, but whether or not it handles streams and how to use it for your specific use case, is a different question.

S.V.
  • 1,181
  • 6
  • 23
1

Flutter has a plugin called Flutter Radio https://pub.dev/packages/flutter_radio. The setup is pretty straightforward.

Simply create a new flutter project then add flutter_radio as a dependency in your pubspec.yaml file. Paste the following code into your main.dart, replace the url string with your url then build and run the project on your emulator and wola!

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter_radio/flutter_radio.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

  String url = "https://ia802708.us.archive.org/3/items/count_monte_cristo_0711_librivox/count_of_monte_cristo_001_dumas.mp3";

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

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

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Audio Plugin Android'),
        ),
        body: new Center(
          child: Column(
            children: <Widget>[
              FlatButton(
                child: Icon(Icons.play_circle_filled),
                onPressed: () => FlutterRadio.play(url: url),
              ),
              FlatButton(
                child: Icon(Icons.pause_circle_filled),
                onPressed: () => FlutterRadio.pause(),
              )
            ],
          )
        ),
      ),
    );
  }
}
theDoron1
  • 53
  • 5