Letti42Lvl 6
- Windows
it works for me, it doesn't load directly on the media endpoint but it still definitely loads in code.org
it works for me, it doesn't load directly on the media endpoint but it still definitely loads in code.org
Letti42 I've built my own song loader it's how i got YT music to work in CDO i don't think i had too many issues with it i just built a loader that will continually try to load the music into it and if it fails it just sends it again since the timeout thing was annoying and i did run into that issue at some point
do note that you also have to encode the URI of the https:// request of the second part since i don't think CDO sanitizes that stuff
playSound("https://studio.code.org/media?u=https%3A%2F%2Fdl.sndup.net%2Fdbs8%2Felectromedieval.mp3")
this works for me
do note if you wish to cache files into CDO and remove them from the original source the caching is iffy and may last for about 24 hours max and will be discarded if there isn't a host upkeeping the content
Varrience I'm trying to load it through this:
https://cdo-backend.onrender.com/fetch?url=https://dl.sndup.net/dbs8/electromedieval.mp3&test=1
which then links to a URL like this:
https://cdo-backend.onrender.com/audiocache/electromedieval.mp3?id=712224333549 (the id will change)
When I open the audiocache in the browser it works, however, I can't get it to load via playSound.
The AI generated music won't work in playSound either, and getting that to work is the end goal:
https://cdo-backend.onrender.com/ai/facebook/musicgen-small?data=%7B%22inputs%22%3A%22a%20chill%20song%20with%20influences%20from%20lofi%2C%20chillstep%20and%20downtempo%E2%80%8BPreview%22%2C%22parameters%22%3A%7B%7D%2C%22options%22%3A%7B%22use_cache%22%3Atrue%2C%22wait_for_model%22%3Atrue%7D%7D&test=1
Varrience do note if you wish to cache files into CDO and remove them from the original source the caching is iffy and may last for about 24 hours max and will be discarded if there isn't a host upkeeping the content
I was thinking about having the user download the image through the cdo cache, especially since I need to clear the audiocache after a request happens to prevent running out of memory
playsound doesn't work if there's characters after the .mp3, you need to load any arbitrary data BEFORE. the url has to end with ".mp3".
What I do to get around this is i use params instead of query, so the url would be
https://cdo-backend.onrender.com/audiocache/<id>/electromedieval.mp3
if you're using express for this it's pretty simple, just do app.get("/somepath/:idparam/songname.mp3", ...
the colon there allows for any id to be passed and you access it with req.params["idparam"]
Varrience that is dumb, but it is also good to know
funny enough i emailed cdo support abt this over a year ago and they still havent fixed it 💀
Letti42
I wonder what happens if you do a different format like this:
https://example.com/path/to/music.wav?param=song.mp3
That should mean you could also get data like this though:
https://example.com/path/to/music.mp3?query=data&a=a.mp3
Though, in my case, just using URL params is shorter & nicer
DragonFireGames i thought about that too, but I've never had to use query parameters too much. does it work? have you tried it?
Varrience Kinda off topic, but have you tried chunking the data for the yt-video thing?
Since I don't know if the bottleneck is in the actual fetching of the mp4 data, splicing that into frames, or loading those frames in code.org. If it's the middle one, it might be faster to splice it in chunks and load those video chunks at a delay. If it's the latter, then you can just send the frames in chunks. You could also try doing that for the audio as well, not sure how well it'd work though.
Letti42 Just tried it, it works
I used this on the server
app.get("/test", async (req, res) => {
console.log(req.query);
var data = await fetch("https://dl.sndup.net/dbs8/electromedieval.mp3");
var blob = await data.blob();
res.set("Content-Type", blob.type);
var arrbuf = await blob.arrayBuffer();
var buf = Buffer.from(arrbuf);
res.send(buf);
});
Then I ran this in the console and heard a sound.
playSound("https://your.server/test?data=test&u=a.mp3")
Checking the logs I found:
{ data: 'test', u: 'a.mp3' }
DragonFireGames ffmpeg runs like dogwater in general that chunking may be faster but you'd have to wait more in between even slicing mp3's into chunks takes a bit.... you'd have to come up with some chunking system that allows for fast separation and rejoining which then requires subsections to be managed within the data, so you'd have to manage that and if your not caching it will definitely be longer than just me rendering videos like I've shown before
ffmpeg is good if you have specs though don't get me wrong
maybe with the right server that would be possible
and sure you probably could separate the data by yourself but i think it's pretty minimal though you could try though it's going to require a lot more memory management though
Varrience Well, I'm assuming that you are not caching it. Perhaps slicing a video into 5 second segments and then cutting up the frames would be faster. At least you could start watching the video. The idea is that while you watch a segment, the next one is being cut up and sent.
DragonFireGames maybe so.... you could take a shot at it, i was pretty satisfied with my music player the video player requires much more space and storage and you'll probably be able to run like 1 video with active chunking unless you plan on making a powerful server to handle it, that's not the only thing though CDO has an image cache limit of which i don't remember the exact number but it will fail after it has too many images.... either that or referencing CDO storage loadins made it crash idk which but that's something to keep in mind as well
not only that there tends to be some failure rate with transferring the data as well and could possibly overwhelm the host or CDO depending on how your going to store it as well
Varrience Well, for my gif loader, I actually stack the images on top of one-another into a spritesheet and then turn that into the builtin cdo animations
window.loadGIF = function(url,speed,callback,callback2,failure) {
var serverurl = server+"/gif?url="+url;
var gif = {};
gif.width = 1;
gif.height = 1;
gif.draw = function() {};
loadImage(url,function(frame) {
gif.width = frame.width;
gif.height = frame.height;
gif.draw = function(x,y,width,height) {
image(frame,x,y,width,height);
};
loadImage(serverurl, function (sheetImage) {
var spriteSheet = loadSpriteSheet(sheetImage, frame.width, frame.height, sheetImage.height/frame.height);
gif.animation = loadAnimation(spriteSheet);
gif.animation.offX = frame.width/2;
gif.animation.offY = frame.height/2;
gif.animation.frameDelay = speed || 4;
gif.draw = function(x,y,width,height) {
translate(x,y);
scale(width/this.width,height/this.height);
this.animation.draw();
scale(this.width/width,this.height/height);
translate(-x,-y);
};
if (typeof callback == 'function') callback(gif);
}, failure);
if (typeof callback2 == 'function') callback2();
},failure);
return gif;
};
Server
var gm = require("gm");
var request = require("request");
app.get("/gif", async (req, res) => {
let url = req.query.url;
if (!url) return;
console.log("Starting: " + url);
gm(request(url))
.coalesce()
.append()
.toBuffer((err, buffer) => {
if (err) {
throw err;
} else {
console.log("Done with: " + url);
res.set("Content-Type", "image/png");
res.send(buffer);
//fs.writeFile("/cache/"+encodeURIComponent(url)+".png",buffer)
}
});
});
DragonFireGames hmm that might work..... idk how much frames you can run into the animation thing though I've never really played around with it much so it might be possible given that you could run a gif with an mp3 in sync well besides the animation maker for my emulator obviously you'd basically be making a pseudo m3u8 file