streaming_radio_flutter_plugin 1.7.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new79

Flutter Streaming Radio Plugin #

This is a simple radio streaming plugin, with foreground notification control for Android and iOS. The plugin has several customization options and allows audio streaming using ExoPlayer for Android and AVPlayer for iOS. The code is fully developed in Swift and Kotlin. You can customize the url and the notification strings for the controls and the feedback. Any reported problems will be welcome. Thank you in advance and I hope you enjoy it.

Setup instructions #

Android #

If you use a http protocol you need to add a NetworkConfig to allow http to your domain into the Manifest file.

Support Android SDK min version : 16

iOS #

Like Android if you use http connection, you must change the info.plist of your project to allow it. You need to change the App Transport Security Settings. For a better functionality in background i recommend to add the Audio Background mode capability in the target of your project.

Feature included #

The plugin can reproduce audio for a streaming source using ExoPlayer for Android and AvPlayer for iOS. You can control the play stop and pause action with the plugin methods or from the foreground notification actions. The plugin have methods to get feedback of the of the player status in the native side to use that in flutter side. You can customize the foreground notification controls messages and button texts with the config method.

How use it in Flutter #

Class StreamingController{

  MethodChannel _channel;
  var  streamingController =  StreamController<String>();

  StreamingController() {
    _channel = const MethodChannel('streaming_channel');
    _channel.setMethodCallHandler((MethodCall call) async {
      switch (call.method) {
        case 'playing_event':
          streamingController.sink.add(call.method);
          return 'Playing, ${call.arguments}';
        case 'paused_event':
          streamingController.sink.add(call.method);
          return 'Paused, ${call.arguments}';
        case 'stopped_event':
          streamingController.sink.add(call.method);
          return 'Stopped, ${call.arguments}';
        case 'loading_event':
          streamingController.sink.add(call.method);
          return 'Loading, ${call.arguments}';
        default:
          throw MissingPluginException();
      }
    });
  }

  Future<void> config({String url,}) async {
    try {
      String result =
      await _channel.invokeMethod('config', <String, dynamic>{
        'url': url,
        'notification_title':"Test " ,
        'notification_description': "Description",
        'notification_color':"#FF0000",
        'notification_stop_button_text': "Stop",
        'notification_pause_button_text': "Pause",
        'notification_play_button_text': "Play",
        'notification_playing_description_text': "Playing",
        'notification_stopped_description_text': "Stopped"

      });
      return result;
    } catch (err) {
      throw Exception(err);
    }
  }


  Future<void> play() async {
    try {
      String result =
      await _channel.invokeMethod('play',<String, dynamic>{});
      return result;
    } catch (err) {
      throw Exception(err);
    }
  }

  Future<void> pause() async {
    try {
      String result =
      await _channel.invokeMethod('pause', <String, dynamic>{});
      return result;
    } catch (err) {
      throw Exception(err);
    }
  }

  Future<void> stop() async {
    try {
      String result =
      await _channel.invokeMethod('stop', <String, dynamic>{});
      return result;
    } catch (err) {
      throw Exception(err);
    }
  }

  void dispose(){
    streamingController.close();
  }

 }

1.0.0 #

  • This first release include implementation od the plugin for Android and iOS and an example to implement it in a flutter project.

1.1.0 #

  • This version contain a update in the .podspec of ios project to avoid issue with wrong plugin name
  • Update documentation

1.2.0 #

  • Update documentation

1.3.0 #

  • Corrections for pods in iOS

1.4.0 #

  • More Corrections for pods in iOS

1.5.0 #

  • Fix issue in Android with stopped event

1.6.0 #

  • Fix missing READ_PHONE_STATE permission in AndroidManifest.xml

1.7.0 #

  • Fix wrong permission in AndroidManifest.xml

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:streaming_radio_flutter_plugin_example_project/StreamingController.dart';

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

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

class _MyAppState extends State<MyApp> {
  var streamingController = StreamingController();

  @override
  void initState() {
    super.initState();
    streamingController.config(
        url: "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              FlatButton(
                onPressed: () {
                  streamingController.play();
                },
                child: Text(
                  "Play",
                ),
              ),
              FlatButton(
                onPressed: () {
                  streamingController.pause();
                },
                child: Text(
                  "Pause",
                ),
              ),
              FlatButton(
                onPressed: () {
                  streamingController.stop();
                },
                child: Text(
                  "Stop",
                ),
              ),
              StreamBuilder(
                stream: streamingController.streamingController.stream,
                builder: (BuildContext context, snapshot) {
                  if (snapshot.hasData) {
                    return new Text(
                      snapshot.data,
                      style: Theme.of(context).textTheme.headline4,
                    );
                  } else {
                    return new Text("", style: Theme.of(context).textTheme.headline4,
                    );
                  }
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  streaming_radio_flutter_plugin: ^1.7.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:streaming_radio_flutter_plugin/streaming_radio_flutter_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
58
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on May 23, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health issues and suggestions

Document public APIs. (-1 points)

4 out of 4 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test