mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
Internet midi respects start and end times (#43021)
* Play Internet Sound respects start time For example, adding &t=400 to youtube links. Doesn't try to parse the start time, youtube-dl does that for us already. Will probably work on most sites not just youtube. * [Play Internet Sound] now supports end time too Switched event handler for start to loadeddata from canplay loadeddata fires when the first frame is available this is quicker and more consistent than canplay, which tries to predict at least a few moments of playability being available before it fires * [Internet Sound] music_extra_data now starts null
This commit is contained in:
@@ -65,6 +65,8 @@ var opts = {
|
||||
'volumeUpdateDelay': 5000, //Time from when the volume updates to data being sent to the server
|
||||
'volumeUpdating': false, //True if volume update function set to fire
|
||||
'updatedVolume': 0, //The volume level that is sent to the server
|
||||
'musicStartAt': 0, //The position the music starts playing
|
||||
'musicEndAt': 0, //The position the music... stops playing... if null, doesn't apply (so the music runs through)
|
||||
|
||||
'defaultMusicVolume': 25,
|
||||
|
||||
@@ -545,6 +547,7 @@ function ehjaxCallback(data) {
|
||||
} else if (data.adminMusic) {
|
||||
if (typeof data.adminMusic === 'string') {
|
||||
var adminMusic = byondDecode(data.adminMusic);
|
||||
var bindLoadedData = false;
|
||||
adminMusic = adminMusic.match(/https?:\/\/\S+/) || '';
|
||||
if (data.musicRate) {
|
||||
var newRate = Number(data.musicRate);
|
||||
@@ -554,6 +557,19 @@ function ehjaxCallback(data) {
|
||||
} else {
|
||||
$('#adminMusic').prop('defaultPlaybackRate', 1.0);
|
||||
}
|
||||
if (data.musicSeek) {
|
||||
opts.musicStartAt = Number(data.musicSeek) || 0;
|
||||
bindLoadedData = true;
|
||||
} else {
|
||||
opts.musicStartAt = 0;
|
||||
}
|
||||
if (data.musicHalt) {
|
||||
opts.musicEndAt = Number(data.musicHalt) || null;
|
||||
bindLoadedData = true;
|
||||
}
|
||||
if (bindLoadedData) {
|
||||
$('#adminMusic').one('loadeddata', adminMusicLoadedData);
|
||||
}
|
||||
$('#adminMusic').prop('src', adminMusic);
|
||||
$('#adminMusic').trigger("play");
|
||||
}
|
||||
@@ -595,6 +611,27 @@ function sendVolumeUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
function adminMusicEndCheck(event) {
|
||||
if (opts.musicEndAt) {
|
||||
if ($('#adminMusic').prop('currentTime') >= opts.musicEndAt) {
|
||||
$('#adminMusic').off(event);
|
||||
$('#adminMusic').trigger('pause');
|
||||
$('#adminMusic').prop('src', '');
|
||||
}
|
||||
} else {
|
||||
$('#adminMusic').off(event);
|
||||
}
|
||||
}
|
||||
|
||||
function adminMusicLoadedData(event) {
|
||||
if (opts.musicStartAt && ($('#adminMusic').prop('duration') === Infinity || (opts.musicStartAt <= $('#adminMusic').prop('duration'))) ) {
|
||||
$('#adminMusic').prop('currentTime', opts.musicStartAt);
|
||||
}
|
||||
if (opts.musicEndAt) {
|
||||
$('#adminMusic').on('timeupdate', adminMusicEndCheck);
|
||||
}
|
||||
}
|
||||
|
||||
function subSlideUp() {
|
||||
$(this).removeClass('scroll');
|
||||
$(this).css('height', '');
|
||||
|
||||
Reference in New Issue
Block a user