Spotify API models.player context issue - spotify

We are developing an app for the Spotify platform. We have a problem with the player context.
We offer our users radio stations. These radio stations are not static playlists, they are created dynamically in runtime. The radio playing process is as follows:
We play the first track with the player's playTrack method.
Then, our algorithm determines the next track to be played and sends it to the client
After the currently playing track finishes playing, we load the new track again with player's playTrack method.
The process works fine if the player has no context prior to starting our radios. But if there is a context already (for example, user starts playing a playlist on Spotify, and then starts a radio with our app), the player continues to play the previous context.
playTrack method does not change the current context of the player. Is there a way for playing a single track using the playContext method, or destroying the context of the player?

I'd say that populating a temporary playlist (Playlist.createTemporary) would be the more straightforward implementation. Then your playlist would become the context.
You can still limit the number of songs provided (seems to be desirable in your case) because you can dynamically add new songs to the end of the playlist while it is going. You can also remove songs from the beginning as you go.

Related

What is the most effective way to handle multiple objects independent from all players when making a game with sockets?

For example, let's say I have a random game in which I have 500 independent objects and 10 players.
Independent object is an object that moves in a specific direction per update regardless of what players do (there is no need for players to come into contact with these objects).
Now if a player is shooting (lets say) a bullet, it is easier because it belongs to a specific player therefore it's easier to avoid in game lag. Lets look at something simpler, though, for example a player try to update their position. The typical thing I would do on client & server side would be this :
client side : update the coords of the player + send a message to the server as socket X
server side : receives the message from socket X, updates the coords of the player on the server side +
sends a message with the coords of that same player to all other sockets
When you do the communication like this, everyone will receive the new coords of the player and there will be little to no lag. (It is also sufficient for objects like bullets, because they are created upon firing a player event)
How do you handle 500+ independent objects that move in random directions with random speed all across the map and update them for all players efficiently? (Be aware that their velocity and speed can be changed upon contact with a player). What I've tried so far:
1) Put all of the movement + collission logic on the server side &
notifying all clients with a setTimeout loop & io.emit -
Result : causes massive lag even when you have only 500+ objects and 4 connected players. All of the players receive the server's response way too slow
2) Put all of the movement + collission logic on the client side & notifying the server about every object' position-
Result : To be honest, couldn't encounter much lag, but I am not sure if this is the correct idea as every time an object moves, I am literally sending a message to the server from each client to update that same object (server is getting notified N[number of connected clients] amount of times about that same object). Handling this entirely on the client side is also a bad idea because when a player randomly switches tabs [goes inactive], no more javascript will be executed in that players' browser and this whole logic will break
I've also noticed that games like agar.io, slither.io, diep.io, etc, all of them do not really have hundreds of objects that move in various directions. In agar.io and slither you mainly have static objects (food) and players, in diep.io there are dynamical objects, but none of them move at very high speeds. How do people achieve this? Is there any smart way to achieve this with minimal lag?
Thanks in advance
Convert your user interactions to enumerated actions and forward those. Player A presses the left arrow which is interpreted by the client as "MOVE_LEFT" with possible additional attributes (how much, angle, whatever) as well as a timestamp indicating when this action took place from Player A's perspective.
The server receives this and validates it as a possible action and forwards it to all the clients.
Each client then interprets the action themselves and updates their own simulation with respect to Player A's action.
Don't send the entire game state to every client every tick, that's too bloated. The other side is to be able to handle late or missing actions. One way of doing that is rollback where you keep multiple sets of state and then keep the game simulation going until a missinterpretation (late/missing packet) is found. Revert to the "right" state and replay all the messages since in order to get state to correct. This is the idea behind GGPO.
I suggest also reading every article related to networking that Gaffer on Games goes into, especially What Every Programmer Needs To Know About Game Networking. They're very good articles.

Partial playback using playbackDuration/startTime in Google Cast Chrome API (v3)

I am trying to cast just a snippet of a file (say, only from 00:00:30 to 00:00:40) from a Chrome sender to the default receiver. Reading the API reference documentation documentation for LoadRequest, MediaInfo, and QueueItem, it seemed like I should be able to do this with some combination of these. In particular, the first queued item (loaded with CastSession#loadMedia) would need LoadRequest#currentTime set to the offset (30 seconds in my example above) and MediaInfo#duration set to the duration (10 seconds in my example), while subsequently queued items would set QueueItem#startTime and QueueItem#playbackDuration to the offset and duration (respectively).
However, this isn't happening in practice. I can confirm that the queue on the receiver has these fields set, but the no matter how I go about this, I can't get the right snippet to play. When I add the first media item as described above, the receiver just plays the track from beginning to end, neither respecting the offset nor the duration. Since the combination of LoadRequest#currentTime and MediaInfo#duration is a bit odd, I tried using only the QueueItem method (add the first media item with autoplay = false, add another queue item, remove the first, and then start playing the queue). In this case, the offset was still not respected, and the duration ended up being (very strangely) the sum of startTime and playbackDuration (in addition, any subsequently queued items would load, and then "finish" playing without starting, which I also can't figure out).
Does anyone else have experience with this part of the API? Am I reading the documentation incorrectly and what I'm doing just isn't supported, or am I just piecing things together incorrectly?
I am not sure I understand why you are attempting to use a queue with multiple items. First, the duration field is not what you think it is; it is not the duration of play back that you want, it is the total duration of the media that is being loaded, regardless of where you start or stop the playback. In fact, in most cases, you don't even need to set that; the receiver gets the total duration of the media when it loads he item, at least in the majority of the cases. The currentTime should work (if it is not, please file a bug on our SDK issue tracker) and alternatively, you can load a media (with autoplay off) and "seek" to the time you want and then play. To stop at a certain point, you need to monitor the the playback location and when it reaches that point, pause the playback.

Music replay does not work on Libgdx

I have a sound track for my game, which I play when player enters a level, and stop when the level ended.
Sound track is a Music class with looping set to true, and loaded through an AssetManager.
It works fine for the first level, I can hear the music, and when the level ends, I call stop. On the start of the second level, I cal start again, but I cannot hear any music. There is no error or exception either.
From the documentation, I thought I can user the same Music class instance, so theoretically it should work AFAIK.
Any idea why it doesn't work?

J2ME Manager.CreatePlayer() freeze application for a split second when using the first time

When I call for the first time to Manager.CreatePlayer() its freezes my application for a split second and it's a problem for me because I'm writing a game and it's noticeable, what can I do to fix it ?
As far as I know, the common logics for game are :
Display loading screen
Here's all heavy operations are prepared/preloaded and cached, so the game can run smoothly later.
Methods that usually called here are Manager.createPlayer and Player.prefetch().
All the image & sound is prepared first, and can be used quickly when game started.
Start the game (loop)
As the resource have been prepared/preloaded, now you can use (draw/play) them here.
Use the Player instances that has been created & prefetched (from loading screen).
You can call Player.start() method here to play the sound.
You can read about the Player state (especially about prefetch) HERE.
Notice that you can reuse the Player instance and call start() method multiple times for playing the same sound. No need to call createPlayer again.

Cocoalibspotify, how to trigger an action when playlist plays the next track

I have a playlist, and I want to sequentially play through the tracks, but every time a new track is loaded, I want to call a function. How would I go about listening for this event?
SPPlaybackManager, the playback class in CocoaLibSpotify, doesn't automatically play tracks sequentially, so you have to manually tell it to play each time. Since you're managing that, you already know when a new track is starting playback.
Additionally, SPPlaybackManagerDelegate has a method -playbackManagerWillStartPlayingAudio:, which will let you know when audio starts hitting the speakers.

Resources