Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing media files from assets #5

Open
iLeafSolutionsPvtLtd opened this issue May 8, 2019 · 7 comments
Open

Playing media files from assets #5

iLeafSolutionsPvtLtd opened this issue May 8, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@iLeafSolutionsPvtLtd
Copy link

Please let me know is it possible to play media files from assets? if so how to do it ?

@siddhesh-tamhanekar
Copy link
Owner

siddhesh-tamhanekar commented May 8, 2019

No it's not possible to play local files/ assets from this plugin till now. may be plugin will support in future releases.
you can try google official video player plugin it supports playing local files..

@siddhesh-tamhanekar siddhesh-tamhanekar added the enhancement New feature or request label Jun 1, 2019
@developerpaaji
Copy link

Please don't close issue until It is not solved

@siddhesh-tamhanekar
Copy link
Owner

HI @singhbhavneet Sorry, I closed this because it's not a bug but additional feature which may be added in future releases. after extending my knowledge about GitHub issues, I feel that this issue should be closed when enhancement is done. will keep in mind for the future.

Thanks.

@Sun3
Copy link

Sun3 commented Oct 2, 2019

To use the plugin as-is and load local flutter audio assets you can use the following code to make it happen:

You need to import the path_provider package.

import 'package:flutter/services.dart'; // rootBundle
import 'dart:io'; // File()
import 'package:path_provider/path_provider.dart'; // getApplicationDocumentsDirectory()

onPressed: () async {
  // Read the Flutter asset file and save it to the Android or iOS Application Documents Folder
  final fileName = 'my_audio_file.mp3';
  var bytesData = await rootBundle.load("assets/audios/$fileName");
  String addDocDirectoryPath = (await getApplicationDocumentsDirectory()).path;
  String filePathAndName = addDocDirectoryPath + '/$fileName';
  await File(filePathAndName).writeAsBytes(bytesData.buffer.asUint8List());

MediaPlayer player;
  MediaFile song1 = MediaFile(
    title: "Song 1",
    type: "video",
    source: filePathAndName,
    desc: "Note from Apple",
  );
},

@szbk
Copy link

szbk commented Dec 5, 2019

@Sun3 This method did not work?

@stevenosse
Copy link

Ability to play an audio file from local storage?

@imaginashaun
Copy link

Just convert the source to a Uri before passing it to the player.

Uri.file("yourpath/yourfile.ext", windows: true).toString()

String sourceFile = Uri.file("yourpath/yourfile.ext", windows: true).toString()
MediaFile(
              title: "Title",
              type: "audio",
              source: sourceFile,
              desc: "Desc here and whater else",
            )


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants