I am currently using the Web Player SDK / Web Api to control spotify playback in my application. The current issue I am running into is that whenever I play a song, I cannot detect the end of the playback of the song because the
state.track_window.next_songs
when listening through
player.addListener('player_state_changed', state => { });
always has items in the "Play Queue", which causes detection almost impossible.
this:
state && state.paused && state.context && state.context.metadata && state.context.metadata.uri == null typically works for, however in the case that state.track_window.next_songs has anything in it, paused is never triggered.
I am wondering if anyone has a solution for this, or if there is a way to clear our the play queue for a specific spotify player instance?
Thanks!
I'm not sure if I understood correctly, but if you want to detect when a song finished playing you can have an object called currentlyPlaying with the ID of the currently playing song and then when there is a state update, check the ID of the state.current_track. If it's different from your currentlyPlaying.id then it means the song finished and the next one started.
----- EDIT ------
There is a way to have the next_tracks array empty. If you play songs using the "uris" body parameter you can add an array of songs to play and in the end of it the next_tracks array is empty. See this screenshot:
To achieve this take a look at the Spotify API:
https://developer.spotify.com/console/put-play/?device_id=&body=%7B%20uris%3A%20%5Bspotify%3Atrack%3A3BQHpFgAp4l80e1XslIjNI%5D%20%7D
I am only using the "uris" parameter not the "context_uri" and I am passing only 1 song in the array. After the song is played nothing is played after.
Related
Spending my evenings hobby coding a topography quiz for my daughter. Leveraging the web and Stack Overflow resources, I got an API running on https://ac1976.pythonanywhere.com/api/wereld Hit it and the server will respond with a JSON object comprised of a random country / capital combination, together with a list of 'wrong' answers for the capital. The wrong answers are based on distance to the (correct) capital and are also randomized. So Tokyo won't show up as an answer for the capital of Belgium, but Paris and London may.
On topic: now building a flask app that fetches a response from the aforementioned API, and creates a multiple choice quiz game asking for the capital of the random country, and giving the user 4 multiple choice options.
My main route to do all of this works, and looks like this:
#app.route('/api/continent/', methods=['GET', 'POST'])
def quiz():
if request.method == "GET":
quiz = Game('wereld')
country = quiz.country
answers = quiz.answers
session['capital'] = quiz.capital
return render_template('quiz.html', a1=answers[0], a2=answers[1], a3=answers[2], a4=answers[3], country=country)
else:
answer = request.form['subject']
if answer == session.get('capital'):
return render_template('antwoord.html', answer="Jaaaaa...")
else:
return render_template('antwoord.html', answer="Neee..")
So on hitting the route initially, the server initializes the class Game, which is essentially a wrapper to catch the response from the API and parcel the response with methods for each of the data points we need: country, answers, and capital. These quiz items are stored in similarly named variables country, answers and capital. Country (in the form of a question) and answers (as 4 separate buttons) are used in the HTML template file, presented on hitting the route.
If the user presses one of the four buttons, the second part of the route logic figures out whether the answer was right, or wrong, and sends back a new html view telling the user the answer was right....or wrong.
Okay. All makes sense, right?
Here's my question. How do I autodirect, after say 1 second, back to the 'top of the if loop' so that the code auto refetches a new response from the API, to play another round? I tried to put a simple "While True:" on top of the if / else loop, which works my original terminal version of this quiz...but Flask is not having it. I understand why (it needs a 'GET') but....how to cause a new one?
thanks for your thoughts / guidance / pointing me in the right direction
Arie
How about a meta refresh tag within the header of the HTML page.
After the defined time has expired, you will be redirected to the specified URL.
It would then look something like this.
<meta http-equiv="refresh" content="1; url={{url_for('quiz', _external=True)}}" />
If you want to use JavaScript, a variant with a timeout would also be possible.
const uri = {{url_for('quiz') | tojson}};
setTimeout(() => window.location.replace(uri), 1000);
I currently have an iframe on my site with a vimeo player.
What I need is: the moment the user pauses the video or closes, store the timestamp so that in another when the user returns to the video, it returns at the point of the stored timestamp. Like Netflix video player.
It's possible?
Accessing the timestamp is possible with Vimeo's Player Api. Making use of the timeupdate listener, the current playback position can be saved. As for how the timestamp is saved, there are many different options (you could store the data client side, server side, in a db, etc...). Then when a user returns to the page you could check if a timestamp exists and set the video's playback position accordingly with setCurrentTime()
I'm new to Alexa Skills but meanwhile I've read tons of information and tutorials.
Fortunately, I'm currently able to create my own custom skill (based on PHP) on my own server and it already works using different intents, utterances, slots etc..
Now, I want Alexa to read a list of items (I send via JSON) in PlainText but I can't find any information how to do this.
I assume there are two options (please correct me if I'm wrong):
Sending a JSON answer including one item - Alexa reads this item - the user says e.g. "next" - Alexa requests my server for the next item - my server sends the next JSON answer ... and so on.
Sending a JSON answer including all items in an array - Alexa reads each item one after another.
I'm not sure which solution is possible and how it can be solved.
So, can anyone help me on this or point me to some information?
Both ways are possible and which one to choose depends on what you are listing.
Using AMAZON.NextIntent
If a single list item include item name and some details about it, then reading out it in one go won't be a good user experience. In this case you can use AMAZON.NextIntent to handle users "next" request.
When the user asks for the list, give the first item in your response and keep a track of the item index in response sessionAttributes. You can also set a STATE attribute too, so that you can check this state in AMAZON.NextIntent handler before you give the next item.
"sessionAttributes": {
"index": 1,
"STATE": "LIST_ITEMS"
}
When the user say "next"
check whether the state is LIST_ITEMS and based on the index give the next item from your list. And in sessionAttributes increment the index
More on sessionAttributes and Response Parameters here
Now, if your items are just names then you can read it one after the other.
In both these solutions it is always good to use SSML rather than just PlainText. SSML gives you more control on how your response is spoken.
More on SSML here
I'm doing some searching using the Instagram REST API. Specifically, the endpoint I'm using is /tags/{tag-name}/media/recent. I'm first getting the number of media items with the tag in question using /tags/{tag-name}, which is ~445K. I'm going through all the media items using the 'next_max_tag_id' that comes along with the response. I don't know how long this takes, but at some point, the max IDs start to loop. Not back to back, but as of ~250K, it's just constantly looping over the same 5 next_max_tag_id values.
Am I doing it wrong by counting the number of items I've processed and comparing it to the number of media items I'd previously gotten?
How do you know when you've reached the end of the list?
Look at the answer here:
Instagram realtime get post from callback
I think this scenario is the same as yours.
I was playing with the sample app for glass api - sent a bunch of items to my timeline, but now I cant figure out how to remove them? Will they timeout on their own eventually?
Philosophically, the timeline is not a collection that you're intended to manage like an email inbox. The idea is that as new cards come in, old cards fade into the past.
But, to get into the specifics, the cards will decay. They will no longer appear on your Glass after 7 days, and will decay from your timeline collection in the Mirror API after 30 days.
Some words of warning, though. This decay property isn't part of the API specification, and it's subject to change, do don't depend on this property for any of your development.
Send a REST DELETE operation to the timeline item URL:
DELETE https://www.googleapis.com/mirror/v1/timeline/{id}
They will also expire after a while (currently 7 days on the client and 30 days on the server.)