I am almost done creating my sound cloud streaming custom player, but I would like the option to add the title and artist of the song that is currently playing.
Right now I have this: http://hellkeepers.com/music/examples/sc-player-minimal.html
But I cannot seem to figure out where to find the current track information.
to get an image and the title you can use this code:
//get element by id from your iframe
var widget = SC.Widget(document.getElementById('soundcloud_widget'));
widget.getCurrentSound(function(music){
artwork_url = music.artwork_url.replace('-large', '-t200x200');
$('#song1').css('background', 'url(\"'+artwork_url+'\") ');
//write the title in a div with the id "title"
document.getElementById('title').innerHTML = music.title;
});
normaly you get a link with "-large" at the end and the size is 100x100. If you want other sizes you have to change the end with ".replace" like I did. A list with available sizes can you find here:
https://developers.soundcloud.com/docs/api/reference#tracks (my size 200x200 is not listed but works. Maybe there are more sizes like every hundred px.)
with:
widget.getDuration(function(duration) {
alert(duration);
}
you have the length of the song in milliseconds
with:
widget.getPosition(function(position) {
alert(position);
}
you have the actual poisition of the song in milliseconds. you have to run a loop to get every second the actual time. And probably you have to calculate milliseconds into seconds and minutes.
Late but better then never my answer :D
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 have a simple project. A button adds points one at a time to a counter. I then change the scene via another button and return to the original scene. The point counter has gone back to zero. How do i prevent this?
Many ways to achieve this. But for starters you can save the number in Player Prefs.
"PlayerPrefs` is a class that stores Player preferences between game sessions. It can store string, float and integer values into the user’s platform registry"
So forexample this is your button callback function:
public void ButtonCallback()
{
number++;
PlayerPrefs.SetInt("MyNumber", number);
}
To get the number next time you are in the scene, you can get the number using:
int number = PlayerPrefs.GetInt("MyNumber");
You will probably need to check if number exists in the first place when you launch the scene first time using:
PlayerPrefs.HasKey("MyNumber");
Read up more on this on:
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Okay, so I have spent a large amount of time searching the internet for help on this to no success, so I would like some help.
I am making a game with SpriteKit, and I have decided to implement my own leaderboard style, rather than the clunky Game Center default. I have managed to log the user into GC, but cannot find the correct (and working) Swift 3 code for pulling information from the leaderboard. I want to pull the top 10 score, along with the current user score (if they aren't already in the top 10). The information I would like from them is position, username and score.
I know this is a fairly simple concept, but every tutorial online either uses the default GC view, or is extremely old/outdated code which no longer works. I just need to know how to pull this information from the leaderboard, then I can process it all myself!
Thank you for any help in advance!
It seems like Apple doesn't have proper example code in Swift, but here's a Swift version loosely based on their Objective-C example:
let leaderboard = GKLeaderboard()
leaderboard.playerScope = .global
leaderboard.timeScope = .allTime
leaderboard.identifier = "YourIdentifier"
leaderboard.loadScores { scores, error in
guard let scores = scores else { return }
for score in scores {
print(score.value)
}
}
Note, this is just a translation from Apple's Objective-C code, and I haven't tested it with real data.
If I generate the widget of someone´s like-list e.g. here: and add the parameter "&start_track=" I can only access the first 24 tracks of this playlist. If I set a higher start_track over 24, I always land on the same track. Is this a bug? What can I do to access e.g. track 40 in a like-list?
In order for the playlist widget to be performant it only loads 25 first tracks – adding more as user scrolls down or reaches the end of current 25-tracks set. This means that if you set start_track to anything more than 25, it won't have what to play yet.
We could check for this param and load according to the offset we need, but we don't right now. I'll create a story for this and update the answer if we get to fix this.
I'm using the MPMoviePlayer to play a movie. I want to be able to play the movie and allow the user to skip to a certain time in the film at the press of a button.
I'm setting the currentPlaybackTime property of the player but it doesn't seem to work. Instead it simply stats the movie from the beginning no matter what value I use.
Also I log the currentPlaybackTime property through a button click, it always returns a large number but it sometimes returns a minus value?! is this expected? (e.g. -227361412)
Sample code below:
- (IBAction) playShake
{
NSLog(#"playback time = %d",playerIdle.currentPlaybackTime);
[self.playerIdle setCurrentPlaybackTime:2.0];
return;
}
I have successfully used this method of skipping to a point in a movie in the past. I suspect that your issue is actually with the video itself. When you set the currentPlaybackTime MPMoviePlayer will skip to the nearest keyframe in the video. If the video has few keyframes or you're only skipping forward a few seconds this could cause the video to start over from the beginning when you change the currentPlaybackTime.
-currentPlaybackTime returns a NSTimeInterval (double) which you are printing as a signed int. This will result in unexpected values. Try either casting to int (int)playerIdle.currentPlaybackTime or printing the double %1.3f.