thyagoluciano / flutter_radio

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

volume control is not working #26

Open tarekbazine opened 5 years ago

tarekbazine commented 5 years ago

once I call setVolume() I get this error :

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method setVolume on channel flutter_radio)
E/flutter (27556): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
E/flutter (27556): <asynchronous suspension>
E/flutter (27556): #1      FlutterRadio.setVolume (package:flutter_radio/flutter_radio.dart:124:10)
E/flutter (27556): <asynchronous suspension>
E/flutter (27556): #2      _AudioPlayerState.build.<anonymous closure> (package:tamejida/ui/widgets/audio_palyer1.dart:72:44)
E/flutter (27556): #3      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
E/flutter (27556): #4      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
E/flutter (27556): #5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (27556): #6      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter (27556): #7      TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7)
E/flutter (27556): #8      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (27556): #9      _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter (27556): #10     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (27556): #11     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (27556): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (27556): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (27556): #14     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (27556): #15     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (27556): #16     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (27556): #17     _invoke1 (dart:ui/hooks.dart:250:10)
E/flutter (27556): #18     _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
E/flutter (27556): 
rymesaint commented 5 years ago

i've got no error like that but it cannot set the volume

daneed commented 4 years ago

The reason: the Kotlin implementation misses the setVolume method! So, on Android, it Wont' work, the missing plugin exception will occure. Btw, on iOS, implementation seems to me o.k.

So, what can be done for android? Until the plugin owner does not correct this BUG, then, you can workaround it, from other words, you can solve it locally, in this way:

  1. download flutter_radio from github, and use this as local plugin In pubspec.yaml, write
    flutter_radio: 
    path: ../flutter_radio

    if the directory of flutter_radio is next to the directory of your project.

  2. open FlutterRadioPlugin.kt, goto onMethodCall add an else branch here:
    call.method.equals("setVolume")-> {
          val volume = call.argument("volume") as Double
          radioManager.setVolume(volume.toFloat())
          result.success(null)
    }
  3. open RadioManager.kt, add:
    fun setVolume(volume: Float) {
        service.setVolume(volume)
    }
  4. open RadioService.kt, add:
    fun setVolume(volume: Float) {
        exoPlayer.volume = volume
    }

That's all. Enjoy it! Cheers, DaneeD

erwinsetiawan commented 4 years ago

Please fix this!

pishguy commented 3 years ago

+1