jeromexiong / audio_manager

A flutter plugin for music playback, including notification handling.
MIT License
99 stars 54 forks source link

AudioManager plugin can't handle links without file endings / streams #54

Closed md186 closed 3 years ago

md186 commented 3 years ago

Hey Jerome,

I cant reopen the issue you closed.. The following streaming links from database project doesnt work well with the AudioManager.

var audioFiles = [
    "https://docs.google.com/uc?export=open&id=1SaJWqfQuHnFtL7uqrzfYG31hzOnqDM3r",
    "https://docs.google.com/uc?export=open&id=1FZkFMjQyWguAl0RMAsYDEZ07c_Qf7gjz",
    "https://docs.google.com/uc?export=open&id=1GqrwQ3eRuiil0p-Na_R1tMAvggp9YrbH",
  ];

If youre using links with file type endings like the following example everything works fine and without delay:

var audioFiles = [
    "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3",
    "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3",
    "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"
  ];

The files without mp3 ending are from my firebase project, this is handled in a different way in your Plugin. It’s not able to execute any AudioManager function in a correct way with this url type as you can see in the Demo. Please try to fix the plugin to get Streams working answell,

Code to reproduce:

import 'package:audio_manager/audio_manager.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    // Page selector for tab list
    void _selectPage(int index) {
      print('page index: $index');
      setState(() {
        currentIndex = index;
      });
    }

    // Routes list for tab navigation Android
    final List<Widget> _pages = [
      ScreenA(),
      ScreenB(func: _selectPage),
    ];

    return Scaffold(
      appBar: AppBar(),
      body: _pages[currentIndex],
      bottomNavigationBar: SafeArea(
        child: BottomNavigationBar(
          onTap: _selectPage,
          iconSize: 22,
          currentIndex: currentIndex,
          type: BottomNavigationBarType.fixed,
          items: [
            BottomNavigationBarItem(
              backgroundColor: Theme.of(context).primaryColor,
              icon: Icon(Icons.description),
              label: 'ScreenA',
            ),
            BottomNavigationBarItem(
                backgroundColor: Theme.of(context).primaryColor,
                icon: Icon(Icons.ac_unit_outlined),
                label: 'ScreenB'),
          ],
        ),
      ),
    );
  }
}

class ScreenA extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text('HOME'),
    );
  }
}

class ScreenB extends StatefulWidget {
  Function func;
  ScreenB({Key key, @required this.func}) : super(key: key);
  @override
  _ScreenBState createState() => _ScreenBState();
}

var audioFiles = [
    "https://docs.google.com/uc?export=open&id=1SaJWqfQuHnFtL7uqrzfYG31hzOnqDM3r",
    "https://docs.google.com/uc?export=open&id=1FZkFMjQyWguAl0RMAsYDEZ07c_Qf7gjz",
    "https://docs.google.com/uc?export=open&id=1GqrwQ3eRuiil0p-Na_R1tMAvggp9YrbH",
  ];
var audioIndex = 0;

class _ScreenBState extends State<ScreenB> {

  //var _controller = PageController();
  PlayMode playMode = AudioManager.instance.playMode;

  var globalIndex =0;

  @override
  void initState() {
    // TODO: implement initState

    List<AudioInfo> _list = [];
    for (var i = 0; i < audioFiles.length; i++) {
      _list.add(AudioInfo(audioFiles[i], coverUrl: '', desc: '', title: ''));
    }

    print(_list);

    AudioManager.instance.audioList = _list;
    //AudioManager.instance.intercepter = true;
    AudioManager.instance.play(auto: true);

    super.initState();
  }

@override
void dispose() {
    // TODO: implement dispose
   // AudioManager.instance.release();
    super.dispose();
  }

  var lastPage =0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: [
          IconButton(
            icon: Icon(Icons.close),
            onPressed: () {
              AudioManager.instance.stop();
              widget.func(0);
            },
          ),
        ],
      ),
      body: PageView.custom(
          onPageChanged: (page){
            if(page != lastPage){
              if(lastPage < page){
                print('swipe right');
                lastPage = page;
                setState(() {
                //audioIndex = page;
                AudioManager.instance.next();
                });
              } else{
                print('swipe left');
                lastPage = page;
              }
            }
          },
          //controller: _controller,
          physics: PageScrollPhysics(),
          scrollDirection: Axis.horizontal,
          childrenDelegate: SliverChildBuilderDelegate((ctx, pageIndex) =>
              // GestureDetector(
              //     onPanUpdate: (details) {
              //       if (details.delta.dx < 0) {
              //         _controller.nextPage(
              //             duration: Duration(milliseconds: 200),
              //             curve: Curves.easeInOut);

              //         setState(() {
              //           //audioIndex = pageIndex;
              //           AudioManager.instance.next();
              //         });

              //       }
              //     },
                  //child: 
                  Center(
                      child: Container(
                          width: 200,
                          height: 200,
                          color: Colors.red,
                          child: Text(audioFiles[audioIndex]))))),
    );
  }
}
jeromexiong commented 3 years ago

avplayer unable to play the file without suffix

md186 commented 3 years ago

@jeromexiong Thanks for the answer. How can we say avplayer the suffix in my provided code?

jeromexiong commented 3 years ago

@jeromexiong Thanks for the answer. How can we say avplayer the suffix in my provided code?

convert your urls to .mp3 etc ending

md186 commented 3 years ago

These urls are streams. If a user clicks on the song the url is called. Can you show me an example how to convert it?

jeromexiong commented 3 years ago

iOS is disable to play stream

md186 commented 3 years ago

hm Im really wondering and need your assistance.

"https://docs.google.com/uc?export=open&id=1SaJWqfQuHnFtL7uqrzfYG31hzOnqDM3r",

The thing is I'am able to play the song, its just not working correctly. How can I convert it before playing it? Can you provide me a workaround for this? You can see my code above.

Could you guide me a workaround how to convert the string to mp3 suffix before playing it?

Thank you very much!