(Flutter) How to update the AudioSource of a playlist using Just Audio keeping the shuffled order - flutter

I have a playlist generated with dummy source urls (it only has the source url of the playing audio and the others are fake) and when I click "next" I want to send an api request to get the real source url and update the sources of the playlist.
If I generate a new _playlist with the correct source and I do something like:
_audioPlayer.setAudioSource(_playlist, initialIndex: nextAudioIndex, initialPosition: Duration.zero);
the playlist (sequenceState.effectiveSequence) gets re-shuffled and the next audio of the previous order becomes the first one.
If I only do await _audioPlayer.seekToNext();, I get an error because the audio source is fake and I didn't update it with the api request result.
The reason I have dummy source urls is to not send a lot of requests at the beginning and wait for them. Is there a way to do this?

Related

Is there a way to capture & handle "next" and "previous” using Google Actions with Actions SDK as the fulfillment tool When Media Response was sent?

I'm using the Media Response to play audio in my Actions SDK (Action SDK is being used as the Fulfillment tool in my Actions Console) driven Action. At the end of each audio clip, I'm using the MEDIA_STATUS callback to advance to another mp3 file in a predefined playlist. As a result, users should be able to navigate forwards / backwards.
When testing on my Google Home mini, Google Assistant on Android and Smart Display, I can intercept "next" and advance to the next audio clip (it sends a request with intent of type MEDIA_STATUS). However, I can't properly intercept "previous" Whenever I try, the audio will restart. Real devices seems to be handling this intent on it's own and does not throw any console output (as my webhook is not accessed at all).
Dialog Flow seem to handle "next" and "previous" as follow up intents, but I need to do the same without using Dialog Flow as the Fulfillment tool.
Can anyone please help with this particular problem?
Currently only a FINISHED event is supported for the Media Response. So, you would not be able to handle distinguish between next and previous.
Referring to #Leon Nicholls answer, I am really confused. I followed his Google Audioplayer tutorial/guide which links to an audioplayer template action
You can still download it, and if you unzip it, you will see code that is put there specifically to handle previous and next tracks.
Now it appears Leon is saying that it can't handle previous and next by voice (but buttons appear to work).
Here is the sample code below. There are links to tutorial actions in it, but now all the content has been removed. I simply need blind people to be able to select and play various bit of audio, too long for SSML, which must be navigable (at least next and pause/resume later) may be part of a playlist. How do I achieve this? Suggesting "Media Partner" or "Podcast" is not a solution as neither available in the UK.
// Handle the More/Yes/Next intents
app.intent(['More', 'Yes', 'Next'], (conv) => {
console.log(`More: fallbackCount=${conv.data.fallbackCount}`);
nextTrack(conv, false);
});
// Handle the Repeat/Previous intent
app.intent(['Repeat', 'Previous'], (conv) => {
console.log(`Repeat: ${conv.user.storage.track}`);
nextTrack(conv, false, true);
});
// Select the next track to play from the data
const nextTrack = (conv, intro, backwards) => {
console.log(`nextTrack: ${conv.user.storage.track}`);
let track = data[0];
// Persist the selected track in user storage
// https://developers.google.com/actions/assistant/save-data#save_data_across_conversations
if (conv.user.storage.track) {
conv.user.storage.track = parseInt(conv.user.storage.track, 10);
if (backwards) {

How do I play an audio file when using Fulfillment with Dialogflow

I'm making a Google Assistant action, similar to what Google does when you say "Play an E note".
I've managed to get my nodejs app to reply back the parameter, but now I need to pass an audio file. How do I do that?
The typical way to do this is to place the audio file on a hosting service somewhere (Firebase Hosting is a good choice, particularly if you're also using Firebase Cloud Functions for your Action, but any place that can serve a file via HTTPS works) and then send back SSML as your response that includes the audio.
This might look something like this:
var audioUrl = 'https://example.com/audiofile.mp3';
var msg = `<speak><audio src="${audioUrl}"></audio></speak>`
app.tell( msg );
Adjust this for your own audio file, and you might want to use app.ask() instead of tell if you are prompting the user to reply to your audio.

Facebook API Private Message image expired - How to get new image ? URL signature expired

I'm helping maintain an app that integrates with Facebook, and has lots of archived links to old private message images. Sometimes these images expire, and we go to facebook and request a new image. This works 90% of the time.
About 10% of the time we're getting back a response that we can't tell what the new image is.
What's the proper way to request a new url for an expired Facebook Private Message image, preferably using v2.5 or newer of the Graph API?
Currently we're doing a GET request to Facebook's Graph API using the message id of the private message like so:
https://graph.facebook.com/v2.3/m_mid.XXXXXXXXX:YYYYYYYYY
and that gives us a response that has a bunch of attachments in it. For 90% of use cases, there's a new attachment that has an url or name field with a new filename that contains the old filename, e.g. old file name being XXX, we'd see a new filename like ....XXXX.... in the url field.
attachments [url='*%s*']/image_data/url
attachments [name='*%s*']/image_data/url
or sometimes
picture
but that doesnt match what we get now, which is a bunch of attachments with no way to map to the new image.
We haven't been able to find a graph API way of doing this, but have the following solutions we're considering:
When there's only one attachment in the response, we just use that one url. This works some of the time, but fails when there's more than one image of course
Save more metadata about the image, at worst case an MD5 of the file. Then compare that to MD5's of the other files until we get the one we want. Instead of an MD5, we could consider using info about the file from a HEAD request. All of this is untested.
Update our old message metadata with new metadata whenever this happens, thus avoiding the problem entirely as new image requests would come from the new metadata.

Soundcloud API not fetching all tracks by a user

Iam using the Sound cloud API to fetch tracks by users. But for some reason the tracks that i get back from the API is missing a lot of tracks from the users actual account. The user has about 1000 tracks but my json is only getting a fraction of those.
I'm not sure what the limit of entries in the JSON response is, but I think it's 200. That means, if a user has more than 200 tracks uploaded, and you want to get the tracks, the JSON response only includes 200 tracks, BUT there is a "next_href" cursor. Use that cursor to fetch the next 200 tracks and so on.
For example: if I fetch my latest activities, I only fetch about 30 at a time (setting limit=30). If I want to get more than 30, I just use the next_href cursor.
"next_href": "https://api.soundcloud.com/me/activities.json?limit=30&cursor=asdf1234
(I replaced my cursor with "asdf1234".)
So, just use that cursor for fetching. Hope I could help!

Soundcloud Stratus - Certain tracks not playing

Running Soundcloud stratus player on www.naturesoundmap.com
The vast majority of listings (custom post type) work fine, but if you navigate on the map down to New Zealand (or the island of Niue), there are a few listings where in the last two weeks or so the sounds have stopped playing. eg. http://www.naturesoundmap.com/listing/post-office-bay/ & http://www.naturesoundmap.com/listing/aroha-evening/
I've checked the links & all are ok - you can see this by pressing the 'Listen' button & the track information loads up ok in Stratus, but it doesn't play.
Strangely, two of the sounds which weren't working last week are now fine.
I'm puzzled!
The problem is that the songs have streaming diabled.
Artists on SoundCloud can choose whether to allow external streaming form sites. In the case of say
https://soundcloud.com/naturesounds_nz/aroha-island-crickets
which is one of the songs that does not play, if get it's api return
https://seam.li/json/?url=api.soundcloud.com/tracks/88830021.json?client_id=apigee
(I passed this through a site I run in order to make the json more readable, this is the plain link )
In this json we see the property
"streamable": false
on line 13, and as such it does not have the stream_url property. Therefore when you call stratus using stream_url, since it does not exist undefined is returned. this results in
GET http://stratus.sc/undefined?consumer_key=xxx 404 (Not Found)
Your solution is simply to manually check the soundcloud urls if they are streamable before putting them on your site. Alternatively if the process is automatic just check the streamable property of the song.