Bug 851338 - Implement AudioContext.currentTime; r=roc

This commit is contained in:
Ehsan Akhgari 2013-03-14 21:01:02 -04:00
parent af8c189b5d
commit 659ae889aa
6 changed files with 44 additions and 0 deletions

View File

@ -21,6 +21,7 @@ class nsXPCClassInfo;
#undef GetCurrentTime
#endif
// X11 has a #define for CurrentTime. Unbelievable :-(.
// See content/media/webaudio/AudioContext.h for more fun!
#ifdef CurrentTime
#undef CurrentTime
#endif

View File

@ -191,5 +191,11 @@ AudioContext::DestinationStream() const
return Destination()->Stream();
}
double
AudioContext::CurrentTime() const
{
return MediaTimeToSeconds(Destination()->Stream()->GetCurrentTime());
}
}
}

View File

@ -21,6 +21,12 @@
#include "MediaStreamGraph.h"
#include "nsIDOMWindow.h"
// X11 has a #define for CurrentTime. Unbelievable :-(.
// See content/media/DOMMediaStream.h for more fun!
#ifdef CurrentTime
#undef CurrentTime
#endif
struct JSContext;
class JSObject;
class nsIDOMWindow;
@ -78,6 +84,8 @@ public:
return float(IdealAudioRate());
}
double CurrentTime() const;
AudioListener* Listener();
already_AddRefed<AudioBufferSourceNode> CreateBufferSource();

View File

@ -21,6 +21,7 @@ MOCHITEST_FILES := \
test_AudioListener.html \
test_badConnect.html \
test_biquadFilterNode.html \
test_currentTime.html \
test_delayNode.html \
test_decodeAudioData.html \
test_dynamicsCompressorNode.html \

View File

@ -0,0 +1,27 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test AudioContext.currentTime</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
var ac = new AudioContext();
is(ac.currentTime, 0, "AudioContext.currentTime should be 0 initially");
setTimeout(function() {
ok(ac.currentTime > 0, "AudioContext.currentTime should have increased by now");
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
}, 1000);
});
</script>
</pre>
</body>
</html>

View File

@ -18,6 +18,7 @@ interface AudioContext {
readonly attribute AudioDestinationNode destination;
readonly attribute float sampleRate;
readonly attribute double currentTime;
readonly attribute AudioListener listener;
[Creator, Throws]