Currently my audio won't play on safari and on mobile devices.
It works fine on a normal pc on FireFox, Chrome and IE
var manifest = [
{ id: "correct", src: 'assets/correct.mp3|assets/correct.ogg' },
{ id: "wrong", src: 'assets/wrong.mp3|assets/wrong.ogg' }
];
var queue = new createjs.LoadQueue();
queue.installPlugin(createjs.Sound);
queue.loadManifest(manifest, true);
And I'm calling the play function like this;
createjs.Sound.play("correct");
This function is written inside a function that's called when a user presses a div.
That code looks like it should work. Web Audio is initially muted on iOS devices, but when play is called inside of a user event it unmutes.
There are a couple of possibilities (without seeing the rest of the code):
You are working on iPad 1, which does not support web audio and has html audio disabled by default due to severe limitations.
You are not waiting for the audio to finish loading before calling play:
queue.addEventListener("complete", loadComplete);
The audio file path is incorrect and therefore the load is failing, which you can detect by listening for an error event.
You are using a non-default encoding for the mp3 files that is not supported by Safari. Generally that would break in other browsers as well though.
Safari requires quicktime for html audio to play, so that could be a problem.
Using createjs.Sound.registerPlugins, SoundJS is being set to use an unsupported on mobile plugin, such as FlashPlugin. You can check your current plugin with:
createjs.Sound.activePlugin.toString();
You may find the Mobile Safe Tutorial useful. Hope that helps.
There is a way to hack it, play an empty mp3 then play the audio.
It must load the empty mp3 within mainfest array firstly:
var manifest = [
...
{ id: "empty", src: 'assets/empty.mp3|assets/empty.ogg' }
];
...
Before playing the sound, play the empty mp3:
createjs.Sound.play("empty");
createjs.Sound.play("correct");
Related
We've got a really annoying bug when trying to send mp3 data. We've got the following set up.
Web cam producing aac -> ffmpeg convert to adts -> send to nodejs server -> ffmpeg on server converts adts to mp3 -> mp3 then streamed to browser.
This works *perfectly" on Linux ( chrome with HTML5 and flash, firefox flash only )
However on windows the sound just "stalls", no matter what combination we use ( browser/html5/flash ). If however we shutdown the server the sound then immediately starts to play as we expect.
For some reason on windows based machines it's as if the sound is being buffered "waiting" for something but we don't know what that is.
Any help would be greatly appreciated.
Relevant code in node
res.setHeader('Connection', 'Transfer-Encoding');
res.setHeader('Content-Type', 'audio/mpeg');
res.setHeader('Transfer-Encoding', 'chunked');
res.writeHeader('206');
that.eventEmitter.on('soundData', function (data) {
debug("Got sound data" + data.cameraId + " " + req.params.camera_id);
if (req.params.camera_id == data.cameraId) {
debug("Sending data direct to browser");
res.write(data.sound);
}
});
Code on browser
soundManager.setup({
url: 'http://dashboard.agricamera.co.uk/themes/agricamv2/swf/soundmanager2.swf',
useHTML5Audio: false,
onready: function () {
that.log("Sound manager is now ready")
var mySound = soundManager.createSound({
url: src,
autoLoad: true,
autoPlay: true,
stream: true,
});
}
});
If however we shutdown the server the sound then immediately starts to play as we expect.
For some reason on windows based machines it's as if the sound is being buffered "waiting" for something but we don't know what that is.
That's exactly what's happening.
First off, chrome can play ADTS streams so if possible, just use that directly and save yourself some audio quality by not having to use a second lossy codec in the chain.
Next, don't use soundManager, or at least let it use HTML5 audio. You don't need the Flash fallback these days in most cases, and Chrome is perfectly capable of playing your streams. I suspect this is where your problem lies.
Next, try disabling chunked transfer. Many clients don't like transfer encoding on streams.
Finally, I have seen cases where Chrome's built-in media handling (which I believe varies from OS to OS) cannot sync to the stream. There are a few bug tickets out there for Chromium. If your playback timer isn't incrementing, this is likely your problem and you can simply try to reload the stream programmatically to work around it.
In my manifest file I've add the audio-channel-content in permissions:
"permissions": {
"audio-channel-content":{"description":"Use the audio channel for the music player"}
}
In my index.html I've got an audio tag like:
<audio mozaudiochannel="content" preload="none" src="http://my-stream-url"></audio>
I can play my audio stream during 2mn:
The first one when the phone is unlock.
After 1mn my phone auto-lock the screen and it continue playing for another minute.
Does it possible to play this audio stream more than 1mn after the lock?
Thanks in advance.
The code and permission block you have are correct and I can confirm it is working in Firefox OS 1.1. You can also do the whole thing in Javascript:
audio = new Audio();
audio.preload = 'none';
audio.mozAudioChannelType = 'content';
It's because the wifi is closed after screen shutdown (auto-lock)?
Are you using the dev version of gaia? Wifi is set to always connect in product version.
Is there some HTML5 API that can help me record the screen (screencast)? I know about recording webcams etc, but I need the screen it self. It would help even more if this API was actually implemented in some cross-platform browser.
Screen capture is available as an experimental feature in Chrome, and you must enable it in your browser settings (chrome://flags/#enable-usermedia-screen-capture). Also, it seems to only work on an https connection.
navigator.getUserMedia({
video: {
mandatory: {
chromeMediaSource: 'screen'
// maxWidth: 640,
// maxHeight: 480
}
}
},
function (stream) {
//success! Now set up the video
var video = document.createElement('video');
video.src = window.URL.createObjectURL(stream);
video.autoplay = true;
//you can choose to display the video here or not.
},
function () {
//failure. browser is unable or permission denied
}
);
Once you have the video set up, it is possible to record it. There is a standard drafted for media recording, but it's not implemented in any browsers yet. However, it is still possible. Refer to this demo and sample code for a workaround.
Unfortunately, for now, this solution is available for Chrome only.
Screen capture is possible via the MediaRecorder API, and recording from a hidden canvas.
Here's an example
I just developed an App by using adobe air. It contains some animations with background music in mp3 format. The problem is that the music is very jerky when the animation is playing...
FYI, this is the way how I play audio in flash:new Sound(new URLRequest("m3.mp3")).play()
Have I done anything wrong?
BTW, the funny thing is that if you hit the HOME button, and then come back to the app again, everything plays beautifully...
Without knowing more about the code, it seems like the sound is not fully loaded. The file plays as far as it can, then waits for more data to show up, then continues . . . very jerky. You may have to wait for the sound to load completely before playing it:
var s = new air.Sound();
s.addEventListener(air.Event.COMPLETE, onSoundLoaded);
var req = new air.URLRequest("bigSound.mp3");
s.load(req);
function onSoundLoaded(event)
{
var localSound = event.target;
localSound.play();
}
This code is from Adobe's Sound docs.
I would like to create a simple add-on that would play a different MP3 recording every time the user double clicks a word in a webpage he is visiting and selects a special option from the context menu.
The MP3 files are located on a remote server. Normally I would use JavaScript+Flash to play the MP3 file. In a Firefox add-on, however, I'm unable to load external scripts for some reason (playing the sound works fine if it's the webpage itself that loads the scripts, but of course I need it to work with every website and not just the ones that include the script).
So what's the easiest way to play a remote MP3 file in a Firefox add-on using JavaScript?
This may not entirely solve your question, as I don't BELIEVE it plays MP3s, but I'm not certain.
Firefox has nsISound, which I KNOW can play remote WAV files, as I've tested and proved it.
You may want to test it for yourself and see if it leads you a little closer!
var ios = Components.classes['#mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
var sound = ios.newURI("http://www.yoursite.com/snds/haha.wav", null, null);
var player = Components.classes["#mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
player.play(sound);
Good luck, I hope this at least gets you close!
I know this is an old question, but if someone needs a way to do it:
let player = document.createElement("audio");
player.src = browser.runtime.getURL(SOUND_URL);
player.play();
There is one caveat: the user must have allowed autoplay on the website.
Here is a working code....
var sound = Components.classes["#mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
var soundUri = Components.classes['#mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
soundUri.spec = "chrome://secchat/content/RING.WAV";
sound.play(soundUri);
var window = require('sdk/window/utils').getMostRecentBrowserWindow();
var audio = ('http://example.com/audio.mp3');
audio.play();