* moved "binPlayers" into libEmbedVideo (more modular folder layout)
[lhc/web/wiklou.git] / js2 / mwEmbed / libEmbedVideo / binPlayers / omtk-fx / src / as / Player.as
1 /*
2
3 Copyright 2008 Tor-Einar Jarnbjo
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 */
18
19 package {
20
21 import org.omtk.vorbis.VorbisSound;
22
23 import flash.display.Shape;
24 import flash.display.Sprite;
25 import flash.display.StageAlign;
26 import flash.display.StageQuality;
27 import flash.display.StageScaleMode;
28 import flash.net.*;
29 import flash.events.Event;
30 import flash.text.TextField;
31 import flash.utils.ByteArray;
32 import flash.utils.Endian;
33 import flash.utils.getTimer;
34 import flash.utils.setTimeout;
35 import flash.utils.setInterval;
36 import flash.external.ExternalInterface;
37
38 [ SWF( backgroundColor = '#ffffff', width = '1', height = '1' ) ]
39
40 public class Player extends Sprite {
41
42 private var sound: VorbisSound;
43 private var initialized: Boolean = false;
44
45 public function Player() {
46 if(stage != null) {
47 stage.frameRate = 20;
48 }
49
50 setTimeout(registerJSCallbacks, 100);
51 initialized = true;
52 }
53
54 private function registerJSCallbacks(): void {
55 if (ExternalInterface.available) {
56 ExternalInterface.addCallback("play", playJS);
57 ExternalInterface.addCallback("getMetaData", getMetaDataJS);
58 ExternalInterface.addCallback("getPosition", getPositionJS);
59 }
60 }
61
62 public function playJS(url: String): void {
63 if(sound != null) {
64 sound.stop();
65 }
66 sound = new VorbisSound(new URLRequest(url));
67 sound.addEventListener(Event.COMPLETE, complete);
68 sound.addEventListener(VorbisSound.METADATA_UPDATE, metadataUpdate);
69 sound.play();
70 }
71
72 public function getMetaDataJS(key: String): String {
73 if(sound == null) {
74 return null;
75 }
76 else {
77 return sound.getMetaData(key);
78 }
79 }
80
81 public function getPositionJS(): int {
82 if(sound == null) {
83 return -1;
84 }
85 else {
86 return sound.position;
87 }
88 }
89
90 private function complete(event: Event):void {
91 trace("complete");
92 if(ExternalInterface.available) {
93 ExternalInterface.call("OMTK_P_complete");
94 }
95 }
96
97 private function metadataUpdate(event: Event):void {
98 trace("metadata update: " + sound.getMetaData("TITLE"));
99 if(ExternalInterface.available) {
100 ExternalInterface.call("OMTK_P_metadataUpdate");
101 }
102 }
103
104 }
105
106 }