I was experimenting the Web Audio API
with
var context = new webkitAudioContext();
//alert(context);
//alert(context.createOscillator);
var oscillator = context.createOscillator();
oscillator.connect(context.destination);
oscillator.noteOn(0);
but I get no sound, so I was wondering what I missing
the alert(context) that is commented out prints [object AudioContext]
but the following alert prints undefined
and when i try alert(context.decodeAudioData) its prints that is a function
thank you for the help
Your problem here is the AudioContext differs between browser. For a fixed version see this jsfiddle.
try {
if (! window.AudioContext) {
if (! window.webkitAudioContext) {
bad_browser();
return;
}
window.AudioContext = window.webkitAudioContext;
}
context = new AudioContext();
}
catch(e) {
console.log('Web Audio API is not supported in this browser');
}
var oscillator = context.createOscillator();
oscillator.connect(context.destination);
oscillator.noteOn(0);
Related
I'm creating a research experiment that uses WebAudio API to record audio files spoken by the user.
I came up with a solution for this using recorder.js and everything was working fine... until I tried it yesterday.
I am now getting this error in Chrome:
"The AudioContext was not allowed to start. It must be resumed (or
created) after a user gesture on the page."
And it refers to this link: Web Audio API policy.
This appears to be a consequence of Chrome's new policy outlined at the link above.
So I attempted to solve the problem by using resume() like this:
var gumStream; //stream from getUserMedia()
var rec; //Recorder.js object
var input; //MediaStreamAudioSourceNode we'll be recording
// shim for AudioContext when it's not avb.
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext; //new audio context to help us record
function startUserMedia() {
var constraints = { audio: true, video:false };
audioContext.resume().then(() => { // This is the new part
console.log('context resumed successfully');
});
navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
console.log("getUserMedia() success, stream created, initializing Recorder.js");
gumStream = stream;
input = audioContext.createMediaStreamSource(stream);
rec = new Recorder(input, {numChannels:1});
audio_recording_allowed = true;
}).catch(function(err) {
console.log("Error");
});
}
Now in the console I'm getting:
Error
context resumed successfully
And the stream is not initializing.
This happens in both Firefox and Chrome.
What do I need to do?
I just had this exact same problem! And technically, you helped me to find this answer. My error message wasn't as complete as yours for some reason and the link to those policy changes had the answer :)
Instead of resuming, it's best practise to create the audio context after the user interacted with the document (when I say best practise, if you have a look at padenot's first comment of 28 Sept 2018 on this thread, he mentions why in the first bullet point).
So instead of this:
var audioContext = new AudioContext; //new audio context to help us record
function startUserMedia() {
audioContext.resume().then(() => { // This is the new part
console.log('context resumed successfully');
});
}
Just set the audio context like this:
var audioContext;
function startUserMedia() {
if(!audioContext){
audioContext = new AudioContext;
}
}
This should work, as long as startUserMedia() is executed after some kind of user gesture.
I'm new on iOS, tvOS and Swift. I've been trying to play a video on tvOS App, but the video from a livestream URL which works fine on web. The TVML template and TVJS both works, even the App works if contains a single video URL(.mp4) but when I try with this streaming link it doesn´t work.
This is my TVJS
App.onLaunch = function(options){
console.log("Hello TVML!");
var resourceLoader = new ResourceLoaderJS(NativeResourceLoader.create());
var initialDoc = resourceLoader.getDocument("hello.tvml");
navigationDocument.pushDocument(initialDoc);
initialDoc.addEventListener("play", handleEvent);
initialDoc.addEventListener("select", handleEvent);
}
class ResourceLoaderJS {
constructor(nativeResourceLoader) {
this.nativeResourceLoader = nativeResourceLoader;
this.domParser = new DOMParser();
}
getDocument(name) {
var docString = this.nativeResourceLoader.loadBundleResource(name);
return this.domParser.parseFromString(docString, "application/xml");
}
}
function playVideo(title, url) {
var player = new Player();
var video = new MediaItem('video', url);
video.title = title;
player.playlist = new Playlist();
player.playlist.push(video);
player.play();
}
function handleEvent(event) {
var buttonId = event.target.getAttribute("id");
if(buttonId === "play") {
playVideo("Hello TVML!","https://new.livestream.com/accounts...");
}
}
Yes it is possible to play livestream urls in apple tv tvml. You just have to specify livestream url in the url section of the code. I was able to play .m3u8 format without any modifications to the code.
You can refer following link to get more info on creating the player:
https://developer.apple.com/library/content/samplecode/TVMLAudioVideo/Listings/client_js_application_js.html
Im currently facing an issue where I am using the Facebook plugin v.7.1.0 for Unity. Im distributing through WebGL, but my app needs to be running both on Facebook, but also outside Facebook. When using FB.Init I get a successful callback, which is what I used to use for testing whether on Facebook canvas or not when deploying for WebPlayer.
So my question is, how do I detect whether the WebGL player is on the facebook canvas or not?
This solution is just posted for anyone who would like the same solution as I used.
The solution was to use a jslib plugin as described here http://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
var FacebookCanvasChecker = {
GetSite: function()
{
var url = document.URL;
var returnStr = "";
if (url.indexOf("apps.facebook.com") > -1)
returnStr = "facebook";
else
{
// try with referer
if(document.referrer)
{
url = document.referrer;
if (url.indexOf("apps.facebook.com") > -1)
returnStr = "facebook";
else
returnStr = url;
}
else
returnStr = url;
}
var buffer = _malloc(returnStr.length + 1);
writeStringToMemory(returnStr, buffer);
return buffer;
}
};
mergeInto(LibraryManager.library, FacebookCanvasChecker);
In Unity's WebGL, you can communicate with javascript. link
So, I call a javascript function to check current url by
C#
Application.ExternalCall("GetCurrentUrlType");
JS
function GetCurrentUrlType(){
var url = document.URL;
if (url.indexOf("apps.facebook.com") > -1)
SendMessage("GameObject", "CheckURL", "facebook");
}
Hope this help!!!
We are currently using the soundcloud API SDK for streaming and it does work on desktop but not 100% on mobile. (using responsive html. same api of course)
Sometime track is not lauch ? sometime it is.
I do not have specific error but on chrome network this line is show in red ??
http://api.soundcloud.com/tracks/146926142/stream?client_id=XXXXX
Redirect
We use a function to stream the track.
function streamTrack(id) {
var defer = $q.defer();
// Stream the track
SC.stream('/tracks/' + id, {
useHTML5Audio: false,
waitForWindowLoad: true,
onfinish: _scope.next,
whileplaying: function () {
var _this = this;
// Since we are in a callback, we need to tell angularJS to apply the change
if (timeout1) $timeout.cancel(timeout1);
timeout1 = $timeout(function () {
// Update the progress bar
_scope.progress = (_this.position / currentTrackDuration * 100) + '%';
_scope.timer = moment(_this.position).format('mm:ss');
$rootScope.$broadcast('trackRunning', { timerunning: _scope.timer });
});
}
}, function (sound) {
if (sound) {
defer.resolve(sound);
} else {
defer.reject();
}
});
return defer.promise;
}
If somebody has an idea pls.
Best Regards
Xavier
I've been searching all day for an answer to my problem. I am trying to use the WWW(URL) in Unity with Javascript to send the scores to my sever from my web player game. I have tried several solutions but I am not sure if I've done any of them right since there wasn't a good explanation on any of it. Here is my code at this moment
var url = "http://www.domain.com/folder/page.php";
function start(){
var scoreForm = new WWWForm();
scoreForm.AddField("score", gamecontroller.score);
// Sending request:
var httpResponse = new WWW(url, scoreForm);
// Waiting for response:
yield httpResponse;
var form = new WWWForm();
form.AddField( "score", gamecontroller.score );
var www = new WWW( url, form );
// wait for request to complete
yield www;
// and check for errors
if (www.error == null)
{
// request completed!
} else {
// something wrong!
Debug.Log("WWW Error: "+ www.error);
}
}