How to play Audio sound at startup automatically in GWT - audio

I want to play a sound at start of the GWT client app.
I used the following code
import com.google.gwt.media.client.Audio;
Audio mistakeAudio;
mistakeAudio=Audio.createIfSupported();
if (mistakeAudio!=null) {
mistakeAudio.setSrc("waves/Gong.wav");
mistakeAudio.load();
mistakeAudio.setLoop(true);
mistakeAudio.play();
}
I tested various variations, but finally the sound only plays, if before the command mistakeAudio.play() at least one mouse click happened on the client window. Not even
doing anything..
Is there a workaround - starting really only programmatically?

You can use HTML5 instead:
<audio id="gong" autoplay>
<source src="waves/Gong.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
or use javascript for the autoplay:
<script>
var audio = document.getElementById("gong");
audio.autoplay = true;
audio.load();
</script>
which you could also code in GWT with JsInterop and Elemental2:
HTMLAudioElement audio = (HTMLAudioElement) Document.getElementById("gong");
audio.autoplay = true;
audio.load();

Related

Chrome stops MPEG-DASH playback after some time

I am working on a project which needs to play MPEG-DASH stream playback on top of videojs.
Now the playback of the stream stops playing after 59 seconds.
See below code and error i am getting
<video id="example-video">
<source src="http://hitsradio.videocdn.scaleengine.net/ondemand/play/mp4:sestore8/hitsradio/ZZ Top - Cheap Sunglasses.mp4/manifest.mpd" type="application/dash+xml">
</video>
<script src="path/to/video.js">
<script src="path/to/videojs-dash.js"></script>
<script src="path/to/dash.all.js"></script>
<script>
myPlayer = document.getElementById("example-video");
myPlayer.play()
</script>
Now the error i got in browsers
[60269][bufferController][video] Waiting for more buffer before starting playback.
dash.all.js:11 [60271][scheduleController][audio] Stalling Buffer
dash.all.js:11 [60271][bufferController][audio] Waiting for more buffer before starting playback.
dash.all.js:11 [60272][playbackController] <video> ratechange: 0
This seems to be a bug in video.js. I just tested other web-based players like dash.js, bitmovin's adaptive streaming player and Google's Shaka player and all three of them played the stream without problems.
To the best of my knowledge, video.js uses dash.js for MPEG-DASH playback, so either you're using an old dash.js version (I tested the latest v2.0.0) or there is a problem in the video.js DASH plugin. If the later is the problem you should create an issue in their github repository.

Samsung Smart TV App (not Tizen) audio plays only once

In a Samsung Smart TV App up to 2014 (not Tizen) I have tried two ways to play a short (about a second) audio file and tested it in the 2014 emulator 5.1:
index.html:
<!-- HTML5 audio tag -->
<audio id="audio" src="http://luniks.net/other/0-99A-Z/1.ogg"></audio>
<!-- Player plugin -->
<object id="pluginPlayer" classid="clsid:SAMSUNG-INFOLINK-PLAYER"></object>
Main.js:
Main.keyDown = function() {
var keyCode = event.keyCode;
// arrow left on remote control, just for testing
if (keyCode == 4) {
// HTML5 audio tag
document.getElementById("audio").play();
}
// arrow right on remote control, just for testing
if (keyCode == 5) {
// Player plugin
var playerObj = document.getElementById('pluginPlayer');
playerObj.Play("http://luniks.net/other/0-99A-Z/1.ogg");
}
};
Each way, the audio file is played only once during the app's lifecycle and only plays again when restarting the app.
I am not sure if the sound is muted or if audio doesn't play at all after it played once.
The same with a <video> tag works fine, the video can be repeatedly played without problems.
When a <video> tag is present (defined after the <audio> tag), the <audio> tag does nothing.
When playing audio with the Player plugin while the video is playing, the video continues to play but is muted.
My final goal is to play a series of short audio files while a video that possibly has (low volume) sound is playing. From my experience so far, I can forget about that. Am I right?
Just add loop="true" in the audio tag and test. It works fine for me.

Soundjs on safari and mobile browsers

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");

How to play audio in background with firefox os?

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.

Embed YouTube with sound off

How must the code below be changed to embed this YouTube with sound off?
<embed src="http://www.youtube.com/v/etnh6_omu0w&hl&rel=1&autoplay=1&sound=1" type="application/x-shockwave-flash"
allowscriptaccess="always" allowfullscreen="true" width="200"></embed>
Here's the code as it should be:
you'll need to include this as well in the same folder this code is in:
SWFObject.js
That's just some helper code, I wouldn't worry about it.
code:
<script type="text/javascript" src="swfobject.js"></script>
<div id="ytapiplayer">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/FSz_a_yx9hA&hl&enablejsapi=1&playerapiid=ytplayer",
"ytapiplayer", "425", "356", "8", null, null, params, atts);
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.mute();
}
</script>
Ok I tested that code and I know it works so if you have any problems let me know, happy hacking!
Get the docs here: YouTube Embedded Player Javascript API Reference
It doesn't work in my web browsers. It said my flash player should be version 8+ But I was using flash player 9 with javascript on. I tested on both Firefox 3.11 & IE 7.
I realize, the flash player's support on Firefox is a little bit buggy (update the player several times), some flash movie may still not appear (blank), but on IE it should work fine. But not in your sample code..
Correction: it works on my IE 7.
But not in Firefox 3.11. I wonder, why flash player / SWFObject not getting along with recent firefox. Do you have any tweak or recommendation can be done to make Firefox 3 plays all swf well?
There might be a volume parameter on the embed tag:
Link

Resources