why external audio link doesn't work with tone.js - tone.js

I am trying to play audio samples from my host with tone.js but no sound.
I try this code from tone.js and it work :
const player2 = new Tone.Player("https://tonejs.github.io/audio/berklee/gong_1.mp3").toDestination();
when I change the link "https://tonejs.github.io/audio/berklee/gong_1.mp3" with my direct host link, no sound.

I think it's a problem with your host, (try changing permissions on your file), try this link, it's my host, it works for me.
player = new Tone.Player("https://vivo-vivendo-musica.com/sample/1_Hat.mp3").toDestination();
// play as soon as the buffer is loaded
player.autostart = true;

Related

MoviePy does not write audio to video

My code is as follows:
from moviepy.editor import *
clip = ImageClip(r"image path here")
audio = AudioFileClip(r"audio path here")
final_clip = CompositeVideoClip([clip])
final_clip2 = final_clip.set_audio(audio)
final_clip2 = final_clip2.set_duration(5)
final_clip2.write_videofile("output_video.mp4", fps=1)
I see no reason why this shouldn't work, it just doesn't write any audio to the file. I was wondering if it was something to do with the ffmeg, but reinstalling made no difference. I am convinced at this point that it is a problem with my computer because it seems that no one else in the world is having this problem.
If it helps, the console says that it is writing audio, but the red bar does not actually fill as it does when it writes video. Any help would be great as I am close to giving up.
(for the record any other methods of adding audio to a video with python would be appreciated)

Three.JS - AudioAnalyser() not working with audio source as Stream type in Safari

I'm developing a streaming radio in 3D using Three.JS, I'm sending music as a PeerConnection to my clients attaching a THREE.AudioAnalyser() to display 3D bars that move according to frequencies.
Sound is working great in all platforms, but THREE.AudioAnalyser() with an input source of stream type only works on Chrome, Safari is not working at all :frowning:
var listener = new THREE.AudioListener();
var audio = new THREE.Audio( listener );
audio.setMediaStreamSource( stream );
audioAnalyser = new THREE.AudioAnalyser( audio, 128 );
function loop(){
console.log(audioAnalyser.getFrequencyData());
}
The console.log() of the loop() function should contain an Array of Integers, on Chrome is all good, Safari logs [0,0,0,0,0,0,0,0]
What could be causing this issue? It seems to work everywhere but not on Safari, and also it only seems to fail when the source is a stream.
Not 100% sure, but you might want to connect the output of the AnalyserNode to the destination node. You may want to stick a GainNode with a gain of 0 in between, just in case you don't really want the audio from the AnalyserNode to be played out.

Preloading HTML5 video keeps connection opened

I am working in a web application that provides some (html5 compatible) videos to the user. I am using videojs to show those videos with the "preload" attribute set to "auto".
I am aware that browsers usually only load a portion of the video and that is ok for me. The problem is that it keeps the connection opened with the backend (spring-boot) that is dispatching the video by writing to the OutputStream:
while ((read = input.read(buffer)) > 0) {
output.write(buffer, 0, read); // once video is preloaded, it keeps waiting here
output.flush();
}
After 1 min, if the user doesn't hit the play button, it throws a ClientAbortedException: java.net.SocketTimeoutException.
Is there any way to make the browser close the connection once the preload has finished? (Note that for our system, it is important to close the InputStream as soon as possible if it is not being used).
Yes, I agree. This is an issue.
The sugestion below only will work if you are using playlist and segments, like HLS and DASH.
If you are playing static files (vod) and its segments are cached on the browser's cache, you can restart the player using a set timeout function and reload all settings again, replacing the preload attribute with "none", on the ready event. So, you can control the cache in seconds that you want.
var stopcache = true;
// when ready, cache segments by 5 seconds and restart player
player.on('ready',function(){
setTimeout(function() {
if (stopcache) {
stopcache = false; // avoid repeat
player.preload('none'); // or false if API allows
player.autoplay(false);
player.src('');
player.src({
type:'application/x-mpegURL',
src:'//example.com/hls/stream.m3u8'
});
}
}, 5000);
});
// avoid player reload if user played the file
player.on('play',function(){ stopcache = false; });
This is just a sugestion, I didn't try it but I believe that it will work because the playlist and segments are cached by the browser (vod). I use the same technique when playing live videos, reloading the url when user press play after pause, forcing the player starts from the actual live segment.

AS3: How do I definitively smooth a bitmap image loaded from an outside server

This issue has been following me around for almost a year now, and I want to kill it, for my sake and for the sake of all.
I'm working on some banner ads that need to load in images from a client's site for display. When I tried to do this using AS2, I found out that AS2 doesn't let you do that. It's a bug in the language. There are workarounds for images on the local server, but images loaded from are not allowed to share their BitmapData, so those workarounds don't work. I ended up capitulating after about two months of banging my head against the desk and cursing Macromedia.
Now we are talking about moving to AS3 (finally) and I'm really excited. Or, I was really excited until I started doing some tests for image quality and found that there is very little change in image quality happening here. It's a repeat of my trials with AS2: everything loads perfectly in the IDE, I get all excited, I move the swfs over to the test server to run them online, and POOF - jaggies. Jaggies everywhere.
I've read a number of solutions online, none of which work. They include:
Setting target.content.smoothing to "true". Works great in the IDE. All improvements disappear in the browser.
Setting target.scaleX = target.scaleY to 1.01. It just breaks the swf.
Adding "new LoaderContext(true)" to my parameters for the load command. Does nothing.
Setting target.content.pixelSnapping to "always". Looks perfect in the IDE, not in the browser.
Setting a crossdomain.xml file. The images are showing up - they're being loaded, even if jaggedly, so there must be a functioning crossdomain file on the client's server, right?
So now I'm just stuck, and brokenhearted. Could anyone offer insight on my code, and why it might not be rendering as beautifully as it should be? Here is the client-safe version of the quick demo I am making (only the image URL has been deleted, everything else is as it is now):
import flash.events.Event;
function completeHandler(e:Event) {
e.target.content.pixelSnapping = "always";
e.target.content.smoothing = true;
}
var imgurl:String = "CLIENT'S IMAGE URL HERE";
var imageLoader01:Loader = new Loader();
var image01:URLRequest = new URLRequest(imgurl);
imageLoader01.load(image01);
imageLoader01.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
addChild(imageLoader01);
imageLoader01.x = 2;
imageLoader01.y = 0;
imageLoader01.scaleX = imageLoader01.scaleY = .6;
var imageLoader02:Loader = new Loader();
var image02:URLRequest = new URLRequest(imgurl);
imageLoader02.load(image02);
imageLoader02.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
addChild(imageLoader02);
imageLoader02.x = 100;
imageLoader02.y = 80;
imageLoader02.scaleX = imageLoader02.scaleY = .308;
var imageLoader03:Loader = new Loader();
var image03:URLRequest = new URLRequest(imgurl);
imageLoader03.load(image03);
imageLoader03.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
addChild(imageLoader03);
imageLoader03.x = 200;
imageLoader03.y = 180;
imageLoader03.scaleX = imageLoader03.scaleY = .152;
var bannerLegend:legend = new legend();
addChild(bannerLegend);
Thank you very much in advance. Any help will be sorely appreciated.
Update: Here is the HTML embed code:
<div id="swf_mr_sc_wt_si"></div>
<script type="text/javascript">
<!--
var swfurl = "http://DOMAIN_WITHELD_SORRY/static/AS3.swf?m=DEFAULT&t=" + (new Date().getTime());
swfobject.embedSWF(swfurl, "swf_mr_sc_wt_si", 300, 250, "8.0.0", "");
// -->
</script>
<p>
Hope this helps.
Further Update: We are not listed in the crossdomain.xml file. But we can still load the jagged images. And those images, when loaded into the same swf run in the IDE, are smooth. I think I'm missing understanding of some kind of apocryphal knowledge here, because everything I read points to me being able to do this. This is VERY confusing.
It's because the image you're loading is located on another domain, and that domain's crossdomain.xml does not contain the domain the .swf is residing on, basically giving the .swf "permission" to access the image's pixel data (Yes, just enabling smoothing on an image loaded from another domain requires the same security as when reading the pixel data using BitmapData.draw(), which is a bit curious). When running in local security sandbox the restrictions are more lax, that's why it works running from the IDE.
Even if your domain were among the approved domains in the crossdomain.xml you might need to tell the Flash Player to check the policy file by sending in new LoaderContext(true) as a second argument to Loader.load() when loading the image.
Edit: I originally thought using loadBytes() would be a workaround, but it turns out it's not. I have removed that example code

Flash & SWFObject2 stops flash audio in background tabs

I use SWFObject 2.2 to play sounds for an AJAX based game I have made. I used to use SWFObject 1, and everything worked fine, but when I updated my game, I updated to 2.2. Now, when users try to listen to music on Youtube or Pandora in another tab on Firefox while playing the game, they can't unless they have that tab selected.
What is interesting is that the video doesn't stop playing, just the sound stops working. I run the following javascript in order to stop the sound effect in my flash file, and it seems to stop the sound at the exact same time on Youtube or Pandora:
$('myflashid').doStop();
The following is the actionscript used for my flash file:
import flash.external.ExternalInterface;
snd=new Sound();
snd.attachSound("MySound1");
ExternalInterface.addCallback( "doPlay", this, doPlay );
ExternalInterface.addCallback( "doStop", this, doStop );
function doPlay() {
snd.start();
}
function doStop() {
snd.stop();
}
I am not sure why this fixes it, but if I set the volume to 0 instead of doing snd.stop(); and then set the volume back to 100 when I start it again, it seems to work fine.

Resources