root/tags/flvplayer-2.5/flvplayer.as

Revision 90, 6.9 kB (checked in by jeroen, 13 months ago)

tagged 4.2 mediaplayer and 1.0 desktopplayer and removed 4.2 branch

  • Property svn:executable set to *
Line 
1//--------------------------------------------------------------------------
2// initial variables that might be useful to change
3//--------------------------------------------------------------------------
4
5// toggle for which file to play if none was set in html
6// you can change the 'test.flv' in your filename
7if(!_root.file) { file = 'video.flv' } else { file = _root.file; }
8
9
10// toggle for autostarting the video
11// you can change the 'true' in 'false'
12if(_root.autostart == 'true' || _root.autoStart == 'true') { autoStart = true; }
13else { autoStart = false; }
14
15if(autoStart == true) { clicktext = "Buffering.."; }
16else if (!_root.clicktext) { clicktext = 'Click to play'; }
17else { clicktext = _root.clicktext; }
18
19playText1.text = playText2.text = clicktext;
20
21
22// toggle for the width and height of the video
23// you can change them to the width and height you want
24w = Stage.width;
25h = Stage.height;
26
27//--------------------------------------------------------------------------
28// stream setup and functions
29//--------------------------------------------------------------------------
30
31// create and set netstream
32nc = new NetConnection();
33nc.connect(null);
34ns = new NetStream(nc);
35ns.setBufferTime(10);
36
37// create and set sound object
38this.createEmptyMovieClip("snd", 0);
39snd.attachAudio(ns);
40audio = new Sound(snd);
41audio.setVolume(80);
42
43// attach videodisplay
44videoDisplay.attachVideo(ns);
45videoDisplay.smoothing = true;
46videoDisplay.deblocking = 5;
47
48// Retrieve duration meta data from netstream
49ns.onMetaData = function(obj) {
50        this.totalTime = obj.duration;
51        // these three lines were used for automatically sizing
52        // it is now done by sizing the video to stage dimensions
53        // if(obj.height > 0 && obj.height < Stage.height-20) {
54        // setDims(obj.width, obj.height);
55        // }
56};
57
58// retrieve status messages from netstream
59ns.onStatus = function(object) {
60        if(object.code == "NetStream.Play.Stop") {
61                // rewind and pause on when movie is finished
62                ns.seek(0);
63                if(_root.repeat == 'true') { return; }
64                ns.pause();
65                playBut._visible = true;
66                pauseBut._visible = false;
67                videoDisplay._visible = false;
68                if (!_root.clicktext) { playText1.text = playText2.text = 'Click to play'; }
69                else { playText1.text = playText2.text = _root.clicktext; }
70        }  else if(object.code == "NetStream.Buffer.Full") {
71                playText1.text = playText2.text = "";
72        } else if(object.code == "NetStream.Play.Start") {
73                playText1.text = playText2.text = "Buffering..";
74        }
75};
76
77
78//--------------------------------------------------------------------------
79// controlbar functionality
80//--------------------------------------------------------------------------
81
82// play the movie and hide playbutton
83function playMovie() {
84        if(!isStarted) {
85                ns.play(file);
86                isStarted = true;
87        } else {
88                ns.pause();
89        }
90        pauseBut._visible = true;
91        playBut._visible = false;
92        videoDisplay._visible = true;
93}
94
95// pause the movie and hide pausebutton
96function pauseMovie() {
97        ns.pause();
98        playBut._visible = true;
99        pauseBut._visible = false;
100};
101
102// video click action
103videoBg.onPress = function() {
104        if(pauseBut._visible == false) {
105                playMovie();
106        } else {
107                pauseMovie();
108        }
109};
110
111// pause button action
112pauseBut.onPress = function() {
113        pauseMovie();
114};
115
116// play button action
117playBut.onPress = function() {
118        playMovie();
119};
120
121// file load progress
122progressBar.onEnterFrame = function() {
123        loaded = this._parent.ns.bytesLoaded;
124        total = this._parent.ns.bytesTotal;
125        if (loaded == total && loaded > 1000) {
126                this.loa._xscale = 100;
127                delete this.onEnterFrame;
128        } else {
129                this.loa._xscale = int(loaded/total*100);
130        }
131};
132
133// play progress function
134progressBar.tme.onEnterFrame = function() {
135        this._xscale = ns.time/ns.totalTime*100;
136};
137
138// start playhead scrubbing
139progressBar.loa.onPress = function() {
140        this.onEnterFrame = function() {
141                scl = (this._xmouse/this._width)*(this._xscale/100)*(this._xscale/100);
142                if(scl < 0.02) { scl = 0; }
143                ns.seek(scl*ns.totalTime);
144        };
145};
146
147// stop playhead scrubbing
148progressBar.loa.onRelease = progressBar.loa.onReleaseOutside = function () {
149        delete this.onEnterFrame;
150        pauseBut._visible == false ? videoDisplay.pause() : null;
151};
152
153
154// fullscreen
155if(_root.showfsbutton == "true") {
156        FSBut.onPress = function() {
157                var base = _root._url.substring(0,_root._url.lastIndexOf('/'));
158                getURL(_root._url+"?file="+file+"&autostart=true&fs=true");
159        };
160} else if (_root.fs == "true") {
161        FSBut.onPress = function() {
162                getURL("javascript: history.go(-1)");
163        };
164}
165
166
167
168// volume scrubbing
169volumeBar.back.onPress = function() {
170        this.onEnterFrame = function() {
171                var xm = this._xmouse;
172                if(xm>=0 && xm <= 20) {
173                        this._parent.mask._width = this._xmouse;
174                        this._parent._parent.audio.setVolume(this._xmouse*5);
175                }
176        };
177}
178volumeBar.back.onRelease = volumeBar.back.onReleaseOutside = function() {
179        delete this.onEnterFrame;
180}
181volumeBar.icn.onPress = function() {
182        if (this._parent._parent.audio.getVolume() == 0) {
183                this._parent._parent.audio.setVolume(90);
184                this._parent.mask._width = 18;
185        } else {
186                this._parent._parent.audio.setVolume(0);
187                this._parent.mask._width = 0;
188        }
189}
190
191
192//--------------------------------------------------------------------------
193// resize and position all items
194//--------------------------------------------------------------------------
195function setDims(w,h) {
196        // set videodisplay dimensions
197        videoDisplay._width = videoBg._width = w;
198        videoDisplay._height = videoBg._height = h-20;
199        playText1._x = w/2-120;
200        playText1._y = h/2-20;
201        playText2._x = playText1._x + 1;
202        playText2._y = playText1._y + 1;
203               
204        // resize the controlbar items ..
205        if(_root.fs == "true") {
206                colorBar._y = playBut._y = pauseBut._y = progressBar._y = FSBut._y = volumeBar._y = h-30;
207                playBut._x = pauseBut._x = colorBar._x = w/2-150;
208                colorBar._width = 300;
209                colorBar._alpha = 25;
210                progressBar._x = w/2-133;
211                progressBar._width = 228;
212                FSBut._x = w/2+95;
213                volumeBar._x = w/2+112;
214                videoDisplay._height = h;
215        } else {
216                colorBar._y = playBut._y = pauseBut._y = progressBar._y = FSBut._y = volumeBar._y = h-20;
217                progressBar._width = w-56;
218                colorBar._width = w;
219                volumeBar._x = w-38;
220                if(_root.showfsbutton == "true") {
221                        FSBut._visible = true;
222                        progressBar._width -=17;
223                        FSBut._x = w-55;
224                } else {
225                        FSBut._visible = false;
226                }
227        }
228}
229
230// here you can ovverride the dimensions of the video
231setDims(w,h);
232
233
234
235//--------------------------------------------------------------------------
236// all done ? start the movie !
237//--------------------------------------------------------------------------
238
239// start playing the movie
240// if no autoStart it searches for a placeholder jpg
241// and hides the pauseBut
242
243pauseBut._visible = false;
244if(_root.image) {
245        imageStr = _root.image;
246} else {
247        imageStr = substring(file,0,file.length-3)+"jpg";
248}
249imageClip.loadMovie(imageStr);
250
251
252if (autoStart == true) { playMovie(); }
Note: See TracBrowser for help on using the browser.