Permalink
Browse files

Merge branch 'master' of https://github.com/mozilla/shumway

  • Loading branch information...
2 parents db24faf + ff1eada commit 2994a6850723e1c50e0e36486e32b4521741d1a7 @mbebenita mbebenita committed Jan 4, 2013
View
Binary file not shown.
View
Binary file not shown.
@@ -32,6 +32,7 @@
<script src="../../src/swf/image.js"></script>
<script src="../../src/swf/label.js"></script>
<script src="../../src/swf/shape.js"></script>
+ <script src="../../src/swf/sound.js"></script>
<script src="../../src/swf/text.js"></script>
<!-- Load AVM1 Dependencies -->
@@ -49,6 +49,7 @@
<script src="../../src/swf/image.js"></script>
<script src="../../src/swf/label.js"></script>
<script src="../../src/swf/shape.js"></script>
+ <script src="../../src/swf/sound.js"></script>
<script src="../../src/swf/text.js"></script>
<!-- Load AVM1 Dependencies -->
@@ -32,6 +32,7 @@
<script src="../swf/image.js"></script>
<script src="../swf/label.js"></script>
<script src="../swf/shape.js"></script>
+ <script src="../swf/sound.js"></script>
<script src="../swf/text.js"></script>
<script> console.timeEnd("Load SWF Dependencies"); </script>
@@ -22,6 +22,7 @@ var LoaderDefinition = (function () {
'../../swf/image.js',
'../../swf/label.js',
'../../swf/shape.js',
+ '../../swf/sound.js',
'../../swf/text.js'
];
@@ -78,10 +79,7 @@ var LoaderDefinition = (function () {
symbol = defineShape(swfTag, symbols);
break;
case SWF_TAG_CODE_DEFINE_SOUND:
- symbol = {
- type: 'sound',
- id: swfTag.id
- };
+ symbol = defineSound(swfTag, symbols);
break;
case SWF_TAG_CODE_DEFINE_SPRITE:
var depths = { };
@@ -160,6 +158,7 @@ var LoaderDefinition = (function () {
var frame = { type: 'frame' };
var symbols = this._symbols;
var tagsProcessed = 0;
+ var soundStream = null;
return {
onstart: function(result) {
@@ -201,6 +200,19 @@ var LoaderDefinition = (function () {
}
initActionBlocks[tag.spriteId] = tag.actionsData;
break;
+ case SWF_TAG_CODE_START_SOUND:
+ var startSounds = frame.startSounds;
+ if (!startSounds)
+ frame.startSounds = startSounds = [];
+ startSounds.push(tag);
+ break;
+ case SWF_TAG_CODE_SOUND_STREAM_HEAD:
+ soundStream = createSoundStream(tag);
+ frame.soundStream = soundStream.info;
+ break;
+ case SWF_TAG_CODE_SOUND_STREAM_BLOCK:
+ frame.soundStream = soundStream.decode(tag.data);
+ break;
case SWF_TAG_CODE_EXPORT_ASSETS:
case SWF_TAG_CODE_SYMBOL_CLASS:
var exports = frame.exports;
@@ -535,6 +547,11 @@ var LoaderDefinition = (function () {
}
}
}
+
+ }
+
+ if (frame.startSounds) {
+ root._registerStartSounds(frameNum, frame.startSounds);
}
if (frameNum === 1)
@@ -662,7 +679,12 @@ var LoaderDefinition = (function () {
break;
case 'sound':
symbolInfo.className = 'flash.media.Sound';
- symbolInfo.props = { };
+ symbolInfo.props = {
+ sampleRate: symbol.sampleRate,
+ channels: symbol.channels,
+ pcm: symbol.pcm,
+ packaged: symbol.packaged
+ };
break;
case 'sprite':
var frameCount = symbol.frameCount;
@@ -16,6 +16,7 @@ var MovieClipDefinition = (function () {
this._scenes = { };
this._timeline = null;
this._totalFrames = 1;
+ this._startSoundRegistrations = [];
var s = this.symbol;
if (s) {
@@ -175,8 +176,10 @@ var MovieClipDefinition = (function () {
this._currentFrame = frameNum;
- if (frameNum)
+ if (frameNum) {
this._requestCallFrame();
+ this._startSounds(frameNum);
+ }
},
_requestCallFrame: function () {
this._scriptExecutionPending = true;
@@ -242,7 +245,35 @@ var MovieClipDefinition = (function () {
this._getAS2Object()[name] = instance._getAS2Object();
}
},
+ _registerStartSounds: function (frameNum, starts) {
+ this._startSoundRegistrations[frameNum] = starts;
+ },
+ _startSounds: function (frameNum) {
+ var starts = this._startSoundRegistrations[frameNum];
+ if (!starts)
+ return;
+ var sounds = this._sounds || (this._sounds = {});
+ var loader = this.loaderInfo._loader;
+ for (var i = 0; i < starts.length; i++) {
+ var start = starts[i];
+ var symbolId = start.soundId;
+ var sound = sounds[symbolId];
+ if (!sound) {
+ var symbolPromise = loader._dictionary[symbolId];
+ var symbolInfo = symbolPromise.value;
+
+ var symbolClass = avm2.systemDomain.findClass(symbolInfo.className) ?
+ avm2.systemDomain.getClass(symbolInfo.className) :
+ avm2.applicationDomain.getClass(symbolInfo.className);
+
+ var sound = symbolClass.createAsSymbol(symbolInfo.props);
+ symbolClass.instance.call(sound);
+ sounds[symbolId] = sound;
+ }
+ sound.play();
+ }
+ },
get currentFrame() {
return this._currentFrame || 1;
},
View
@@ -2,9 +2,9 @@ var SoundDefinition = (function () {
var audioElement = null;
- function getAudioDescription(buffer, onComplete) {
+ function getAudioDescription(soundData, onComplete) {
audioElement = audioElement || document.createElement('audio');
- audioElement.src = "data:audio/mpeg;base64," + base64ArrayBuffer(buffer);
+ audioElement.src = "data:" + soundData.mimeType + ";base64," + base64ArrayBuffer(soundData.data);
audioElement.load();
audioElement.addEventListener("loadedmetadata", function () {
onComplete({
@@ -21,6 +21,16 @@ var SoundDefinition = (function () {
this._bytesTotal = 0;
this._bytesLoaded = 0;
this._id3 = new flash.media.ID3Info();
+
+ var s = this.symbol;
+ if (s && s.packaged) {
+ var soundData = s.packaged;
+ var _this = this;
+ getAudioDescription(soundData, function (description) {
+ _this._length = description.duration;
+ });
+ this._soundData = soundData;
+ }
},
close: function close() {
@@ -48,12 +58,15 @@ var SoundDefinition = (function () {
loader.addEventListener("complete", function (event) {
_this.dispatchEvent(event);
- var buffer = loader.data.a;
- getAudioDescription(buffer, function (description) {
+ var soundData = _this._soundData = {
+ data: loader.data.a,
+ mimeType: 'audio/mpeg'
+ };
+ getAudioDescription(soundData, function (description) {
_this._length = description.duration;
});
_this._playQueue.forEach(function (item) {
- playChannel(buffer, item.channel, item.startTime, item.soundTransform);
+ playChannel(soundData, item.channel, item.startTime, item.soundTransform);
});
});
},
@@ -66,15 +79,16 @@ var SoundDefinition = (function () {
},
play: function play(startTime, loops, soundTransform) {
// (startTime:Number = 0, loops:int = 0, soundTransform:SoundTransform = null) -> SoundChannel
+ startTime = startTime || 0;
var channel = new flash.media.SoundChannel();
channel._sound = this;
this._playQueue.push({
channel: channel,
startTime: startTime,
soundTransform: soundTransform
});
- if (this._loader.data) {
- playChannel(this._loader.data.a, channel, startTime, soundTransform);
+ if (this._soundData) {
+ playChannel(this._soundData, channel, startTime, soundTransform);
}
return channel;
},
@@ -102,11 +116,12 @@ var SoundDefinition = (function () {
}
};
- function playChannel(buffer, channel, startTime, soundTransform) {
- channel._element.src = "data:audio/mpeg;base64," + base64ArrayBuffer(buffer);
- channel._element.play();
- channel._element.addEventListener("playing", function () {
- channel._element.currentTime = startTime / 1000;
+ function playChannel(soundData, channel, startTime, soundTransform) {
+ var element = channel._element;
+ element.src = "data:" + soundData.mimeType + ";base64," + base64ArrayBuffer(soundData.data);
+ element.addEventListener("loadeddata", function loaded() {
+ element.currentTime = startTime / 1000;
+ element.play();
});
}
View
@@ -15,10 +15,10 @@ var tagHandler = {
/* DoAction */ 12: DO_ACTION,
/* DefineFontInfo */ 13: undefined,
/* DefineSound */ 14: DEFINE_SOUND,
- /* StartSound */ 15: undefined,
+ /* StartSound */ 15: START_SOUND,
/* DefineButtonSound */ 17: undefined,
- /* SoundStreamHead */ 18: undefined,
- /* SoundStreamBlock */ 19: undefined,
+ /* SoundStreamHead */ 18: SOUND_STREAM_HEAD,
+ /* SoundStreamBlock */ 19: SOUND_STREAM_BLOCK,
/* DefineBitsLossless */ 20: DEFINE_BITMAP,
/* DefineBitsJPEG2 */ 21: DEFINE_IMAGE,
/* DefineShape2 */ 22: DEFINE_SHAPE,
@@ -34,7 +34,7 @@ var tagHandler = {
/* DefineEditText */ 37: DEFINE_TEXT,
/* DefineSprite */ 39: undefined,
/* FrameLabel */ 43: FRAME_LABEL,
- /* SoundStreamHead2 */ 45: undefined,
+ /* SoundStreamHead2 */ 45: SOUND_STREAM_HEAD,
/* DefineMorphShape */ 46: DEFINE_SHAPE,
/* DefineFont2 */ 48: DEFINE_FONT2,
/* ExportAssets */ 56: SYMBOL_CLASS,
@@ -62,7 +62,7 @@ var tagHandler = {
/* DefineSceneAndFrameLabelData */ 86: undefined,
/* DefineBinaryData */ 87: undefined,
/* DefineFontName */ 88: undefined,
- /* StartSound2 */ 89: undefined,
+ /* StartSound2 */ 89: START_SOUND,
/* DefineBitsJPEG4 */ 90: DEFINE_IMAGE,
/* DefineFont4 */ 91: undefined
};
Oops, something went wrong.

0 comments on commit 2994a68

Please sign in to comment.