florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
757 stars 365 forks source link

Assets_audio_player PlatformException(PLAY_ERROR #682

Open branchdev98 opened 2 years ago

branchdev98 commented 2 years ago

Flutter Version

My version : 2.10.4

Lib Version

My version : 3.0.4+1

Platform (Android / iOS / web) + version

Platform : iOS Deployment target 12.0

Describe the bug flutter: PlatformException(PLAY_ERROR, Cannot play assets/audio/001.mp3, The operation could not be completed, null) [VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: PlatformException(PLAY_ERROR, Cannot play assets/audio/001.mp3, The operation could not be completed, null)

Small code to reproduce import 'dart:convert'; import 'dart:io' show Platform; import 'package:assets_audio_player/assets_audio_player.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:StressAbbauen/Config/Constants.dart'; import 'package:StressAbbauen/Models/Posts.dart';

import 'dart:async';

import 'package:StressAbbauen/Screens/Global_File/GlobalFile.dart'; import 'package:StressAbbauen/Services/audioPlayer.dart'; import 'package:http/http.dart' as http;

class SplashScreenPage extends StatefulWidget { @override _SplashScreenPageState createState() => _SplashScreenPageState(); }

class _SplashScreenPageState extends State { final String imagename = 'assets/images/logo.svg'; Widget get svg => SvgPicture.asset( imagename, width: 50, height: 50, color: VtmBlue, );

Future<List> getPosts() async { //calling api

// ignore: non_constant_identifier_names
List<Posts> Listofpost = [];
await http
    .get(Uri.parse(
        "http://blog.vtm-stein.de/wp-json/wp/v2/posts?status=publish&order=desc&per_page=5&page=1&categories=3"))
    .then((res) {
  print(res.body);
  // ignore: non_constant_identifier_names
  var Storedataofpost = jsonDecode(res.body);
  print(Storedataofpost);
  Listofpost = (Storedataofpost as List)
      .map((data) => Posts.fromJson(data))
      .toList();
  print(Listofpost.length);
  /* print(jsonEncode(Listofpost).toString());*/
});
Global.allPosts = Listofpost;
return Listofpost;

}

startTime() async { getPosts();

User user = FirebaseAuth.instance.currentUser;
if (user == null) {
  FirebaseAuth.instance.signInAnonymously().then((value) {
    Global.user = value.user;
  });
} else {
  Global.user = user;
}

**await CommonPlayer.assetsAudioPlayer.open(
    Playlist(
      audios: [
        Audio(
          "assets/audio/001.mp3",
          metas: Metas(
            title: trackone_text,
            artist: aboutTitleText,
            album: trackone_text,
            image: MetasImage.asset(
                "assets/images/bgForPlayer.png"), //can be MetasImage.network
          ),
        ),
        Audio(
          "assets/audio/002.mp3",
          metas: Metas(
            title: introduction_text,
            artist: aboutTitleText,
            album: introduction_text,
            image: MetasImage.asset(
                "assets/images/bgForPlayer.png"), //can be MetasImage.network
          ),
        )
      ],
    ),
    autoStart: false,
    loopMode: LoopMode.none,
    showNotification: true);**

var _duration = new Duration(seconds: 3);
return new Timer(_duration, navigationPage);

} void navigationPage() { Navigator.of(context).pushReplacementNamed('Bottombar'); }

void initState() { super.initState(); startTime(); }

@override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( children: [ Spacer(), Container( height: 200, width: 200, child: SvgPicture.asset( imagename, color: VtmBlue, )), SizedBox( height: 20, ), Text( splashTitle ?? "The Relief of Pain", style: TextStyle(color: VtmBlue, fontSize: 32), textAlign: TextAlign.center, ), Spacer(), Text( splashSubTitle ?? "VTM Dr. Stein", style: TextStyle(color: VtmBlue, fontSize: 28), ), SizedBox( height: 2, ), / Text("Dr.Stein",style: TextStyle( color: VtmBlue,fontWeight: FontWeight.bold, fontSize: 20 ),),/ Spacer(), ], ), ), ); } }

branchdev98 commented 2 years ago

import 'package:assets_audio_player/assets_audio_player.dart';

class CommonPlayer { static AssetsAudioPlayer assetsAudioPlayer = AssetsAudioPlayer(); }

ducanh3005 commented 2 years ago

https://github.com/florent37/Flutter-AssetsAudioPlayer/issues/557#issuecomment-858803707