i am new with using just_audio plugin and i have list of url that i set them into Player like following
AudioPlayer _audioPlayer;
_audioPlayer = AudioPlayer();
_audioPlayer
.setAudioSource(ConcatenatingAudioSource(children: [
AudioSource.uri(Uri.parse(
"https://archive.org/download/IGM-V7/IGM%20-%20Vol.%207/25%20Diablo%20-%20Tristram%20%28Blizzard%29.mp3")),
AudioSource.uri(Uri.parse(
"https://archive.org/download/igm-v8_202101/IGM%20-%20Vol.%208/15%20Pokemon%20Red%20-%20Cerulean%20City%20%28Game%20Freak%29.mp3")),
AudioSource.uri(Uri.parse(
"https://scummbar.com/mi2/MI1-CD/01%20-%20Opening%20Themes%20-%20Introduction.mp3")),
]))
Now How can i use _audioPlayer.play()with one specific url
in other word i need to tell him play the url that has index 3
how implement this , thanks
It seems that the purpose of ConcatenatingAudioSource is to play the children one after the other (or randomly with the shuffle options), as if it was one source. The doc doesn't seem to mention seeking to a specific index. I think you can achieve what you want just by re-setting the audio source every time, no ?
Related
I'm using Flutter just audio and I'm creating a ContatenatingAudioSource like this:
// Define the playlist
final playlist = ConcatenatingAudioSource(
// Start loading next item just before reaching it
useLazyPreparation: true,
// Customise the shuffle algorithm
shuffleOrder: DefaultShuffleOrder(),
// Specify the playlist items
children: [
AudioSource.uri(Uri.parse('https://example.com/track1.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track2.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track3.mp3')),
],
);
This works perfectly, but I can't seem to prevent the next audio from playing when the current one ends.
All I want is a playlist where I have to explicitly seek the next audio, whenever the current one ends.
Is it possible to do that?
It sounds like ConcatenatingAudioSource is not the right solution to your problem, because what it does is "concatenate" the audio of multiple items together so that they can be played continuously.
If all you want is to have separate items that the user can switch between, then you can program it exactly that way:
final items = [
AudioSource.uri(Uri.parse('https://example.com/track1.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track2.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track3.mp3')),
];
Future<void> selectItem(int index) {
await player.setAudioSource(items[index]!);
}
Now, there is only ever one item in just_audio's playlist which means that when it completes, it completes. You can call selectItem(i) to switch to item i.
This solution does mean that player.sequence will not contain a sequence of all items, it will only ever contain a single item. So if you were relying on that to render the list in your UI, you should instead use items (declared above).
I want to play audio by the URL
https://wortcast01.wortfm.org/appfiles/wort_210715_080006buzzthu.m3u
it has a body(with tracks)
https://wortcast01.wortfm.org/pitch/preroll-buzzthu.mp3
https://wortcast01.wortfm.org/mp3/wort_210715_080006buzzthu.mp3
When I set https://wortcast01.wortfm.org/appfiles/wort_210715_080006buzzthu.m3u to the AVPlayer then the duration is equal to Nan. But each track from the list has a duration.
Do you have an idea how to extract duration via AVPlayer?
return Nan:
var itemDuration: Double? {
return currentItem?.duration.seconds
}
AVFoundation(AVPlayer, AVAsset....) automatically marks any .m3u like "Live broadcasting" (my assumption: It looks like Apple uses scenario M3U8 for working with M3U)
Solution:
Create additional functionality which loads m3u(or pls) content, create an internal playlist, and play these internal parts ar AVPlayer.
I'm trying to play two sound tracks at the time, the first one work as a BGM and the other works as a SFX
What happened now is the BGM is playing and when a SFX sound start to play the BGM is stopped and then starts from the beginning.
I want both sounds to be played without stopping, I searched the docs and I couldn't found a clear answer to this.
You can use asset_audio_player to open multiple audio instances.
///play 3 songs in parallel
AssetsAudioPlayer.newPlayer().open(
Audio.asset("assets/audios/song1.mp3")
);
AssetsAudioPlayer.newPlayer().open(
Audio.asset("assets/audios/song2.mp3")
);
//another way, with create, open, play & dispose the player on finish
AssetsAudioPlayer.playAndForget(
Audio.asset("assets/audios/song3.mp3")
);
You can read the documentation fore more info.
You can refer to this question for a more comprehensive answer, but you can simply create two players, one to play the BGM and one to play the SFX:
final bgmPlayer = AudioPlayer();
final sfxPlayer = AudioPlayer();
await bgmPlayer.setAsset('music.mp3');
await sfxPlayer.setAsset('effect.mp3');
bgmPlayer.play(); // start playing background music
// now you can play the sound effect any time you want
// while the BGM continues to play:
await sfxPlayer.play();
await sfxPlayer.play();
await sfxPlayer.play();
I understood this page to mean that queuing in pyglet provides a gapless transition between audio tracks. But when I test it out, there is a noticeable gap. Has anyone here worked with gapless audio in pyglet?
Example:
player = pyglet.media.Player()
source1 = pyglet.media.load([file1]) # adding streaming=False doesn't fix the issue
source2 = pyglet.media.load([file2])
player.queue(source1)
player.queue(source2)
player.play()
player.seek([time]) # to avoid having to wait until the end of the track. removing this doesn't fix the gap issue
pyglet.app.run()
I would suggest you either edit your url1 and url2 into caching them locally if they're external sources. And then use Player().time to identify when you're about to reach the end. And then call player.next_source.
Or if it's local files and you don't want to programatically solve the problem you could chop up the audio files in something like Audacity to make them seamless on start/stop.
You could also experiment with having multiple players and layer them on top of each other. But if you're only interested in audio playback, there's other alternatives.
It turns out that there were 2 problems.
The first one: I should have used
source_group = pyglet.media.SourceGroup()
source_group.add(source1)
source_group.add(source2)
player.queue(source_group)
The second one: mp3 files are apparently slightly padded at the beginning and at the end, so that is where the gap is coming from. However, this does not seem to be an issue with any other file type.
getUserMedia(constrains).then(stream => {
var recorder = new MediaRecorder(stream)
})
recorder.start()
recorder.pause()
// get new stream getUserMedia(constrains_new)
// how to update recorder stream here?
recorder.resume()
Is it possible? I've try to create MediaStream and use addTrack and removeTrack methods to change stream tracks but no success (recorder stops when I try to resume it with updated stream)
Any ideas?
The short answer is no, it's not possible. The MediaStream recording spec explicitly describes this behavior: https://w3c.github.io/mediacapture-record/#dom-mediarecorder-start. It's bullet point 15.3 of that algorithm which says "If at any point, a track is added to or removed from stream’s track set, the UA MUST immediately stop gathering data ...".
But in case you only want to record audio you can probably use an AudioContext to proxy your streams. Create a MediaStreamAudioDestinationNode and use the stream that it provides for recording. Then you can feed your streams with MediaStreamAudioSourceNodes and/or MediaStreamTrackAudioSourceNodes into the audio graph and mix them in any way you desire.
Last but not least there are currently plans to add the functionality you are looking for to the spec. Maybe you just have to wait a bit. Or maybe a bit longer depending on the browser you are using. :-)
https://github.com/w3c/mediacapture-record/issues/167
https://github.com/w3c/mediacapture-record/pull/186