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

Offline listening #2

Closed
emahota-flo opened this issue Jun 26, 2022 · 3 comments
Closed

Offline listening #2

emahota-flo opened this issue Jun 26, 2022 · 3 comments

Comments

@emahota-flo
Copy link

I want use your plugin for caching audio and listening them offline. Could I do it?

I added this plugin in my project. Called dynamicSet() method. After what I turn off internet on the device and try listen audio(play() method) and got exaption
TYPE_SOURCE: java.net.UnknownHostException: Unable to resolve host ": No address associated with hostname

@lau1944
Copy link
Owner

lau1944 commented Jun 26, 2022

Yes, you can do that.

First, get the local downloaded audio file ( make sure to check if the file exists first)

const path = await player.getCachedPath(url: your_remote_url);

Then play the file

await player.playFromFile(filePath: path);

@emahota-flo
Copy link
Author

A lot of thanks!

@lau1944 lau1944 closed this as completed Jun 27, 2022
@otabekoff
Copy link

Hi. I have a question. What is the player here?

const path = await player.getCachedPath(url: your_remote_url);

And here:

await player.playFromFile(filePath: path);

Also, can you have an example to cache many audio files? Should we do it with for loop?

My data is created like this:

import 'package:just_audio/just_audio.dart';
import 'package:just_audio_background/just_audio_background.dart';

final ConcatenatingAudioSource audiosPlaylist = ConcatenatingAudioSource(
  children: [
    AudioSource.uri(
      Uri.parse('https://cdn.pixabay.com/download/audio/2023/03/25/audio_4bc265ac9f.mp3'),
      tag: MediaItem(
        id: '0',
        title: "Ar-Rahiq Al-Maxtum",
        artist: "Safiyyurrahmon Muborakfuriy",
        artUri: Uri.parse(
            'https://img.youtube.com/vi/g-oht-ECif0/maxresdefault.jpg'),
      ),
    ),
    AudioSource.uri(
      Uri.parse('https://sakiyna.com/ar-rahiq-al-maxtum/0-qism.mp3'),
      tag: MediaItem(
        id: '1',
        title: "Ar-Rahiq Al-Maxtum",
        artist: "Safiyyurrahmon Muborakfuriy",
        artUri: Uri.parse(
            'https://img.youtube.com/vi/g-oht-ECif0/maxresdefault.jpg'),
      ),
    ),
  ],
);

And I want to use it with _audioPlayer.setAudioSource(here_AudioSource).

Please give full examples.

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

No branches or pull requests

3 participants