source: trunk/fl5/src/com/longtailvideo/jwplayer/media/ImageMediaProvider.as @ 837

Revision 837, 3.5 KB checked in by pablo, 3 years ago (diff)

Fix ImageMediaProvider (Broken in 835)

RevLine 
[364]1/**
2 * Model for playback of GIF/JPG/PNG images.
3 **/
4package com.longtailvideo.jwplayer.media {
5        import com.jeroenwijering.events.*;
6        import com.longtailvideo.jwplayer.events.MediaEvent;
7        import com.longtailvideo.jwplayer.model.PlayerConfig;
8        import com.longtailvideo.jwplayer.model.PlaylistItem;
[380]9        import com.longtailvideo.jwplayer.player.PlayerState;
[729]10        import com.longtailvideo.jwplayer.utils.Draw;
[802]11        import com.longtailvideo.jwplayer.utils.Logger;
[650]12       
[364]13        import flash.display.*;
14        import flash.events.*;
15        import flash.net.URLRequest;
16        import flash.system.LoaderContext;
17        import flash.utils.*;
[642]18
19
[364]20        public class ImageMediaProvider extends MediaProvider {
21                /** Loader that loads the image. **/
[642]22                private var _loader:Loader;
23                /** ID for the position _postitionInterval. **/
24                private var _postitionInterval:Number;
25
26
[364]27                /** Constructor; sets up listeners **/
[370]28                public function ImageMediaProvider() {
[642]29                        super('image');
[370]30                }
31
[642]32
[370]33                public override function initializeMediaProvider(cfg:PlayerConfig):void {
34                        super.initializeMediaProvider(cfg);
[642]35                        _loader = new Loader();
36                        _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderHandler);
37                        _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
38                        _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
[364]39                }
[642]40
41
[364]42                /** load image into screen **/
43                override public function load(itm:PlaylistItem):void {
44                        _item = itm;
45                        _position = 0;
[642]46                        _loader.load(new URLRequest(item.file), new LoaderContext(true));
[380]47                        setState(PlayerState.BUFFERING);
[512]48                        sendBufferEvent(0);
[364]49                }
[642]50
51
[364]52                /** Catch errors. **/
53                private function errorHandler(evt:ErrorEvent):void {
54                        stop();
[523]55                        error(evt.text);
[364]56                }
[642]57
58
[364]59                /** Load and place the image on stage. **/
60                private function loaderHandler(evt:Event):void {
[642]61                        media = _loader;
[837]62                        sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_LOADED);
[802]63                        try {
64                                Draw.smooth(_loader.content as Bitmap);
65                        } catch (e:Error) {
66                                Logger.log("Could not smooth image file: " + e.message);
67                        }
[650]68                        sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {metadata: {height: evt.target.height, width: evt.target.width}});
69                        sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL);
[364]70                }
[642]71
72
[364]73                /** Pause playback of the_item. **/
74                override public function pause():void {
[642]75                        clearInterval(_postitionInterval);
[364]76                        super.pause();
77                }
[642]78
79
[364]80                /** Resume playback of the_item. **/
81                override public function play():void {
[826]82                        _postitionInterval = setInterval(positionInterval, 100);
[364]83                        super.play();
84                }
[642]85
86
[364]87                /** Interval function that pings the _position. **/
88                protected function positionInterval():void {
[829]89                        if (state != PlayerState.PLAYING) { return; }
90
[642]91                        _position = Math.round(position * 10 + 1) / 10;
92                        if (position < _item.duration) {
[715]93                                sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_TIME, {position: position, duration: item.duration});
[364]94                        } else if (_item.duration > 0) {
[523]95                                complete();
[364]96                        }
97                }
[642]98
99
[364]100                /** Send load progress to player. **/
101                private function progressHandler(evt:ProgressEvent):void {
102                        var pct:Number = Math.round(evt.bytesLoaded / evt.bytesTotal * 100);
[523]103                        sendBufferEvent(pct);
[364]104                }
[642]105
106
[364]107                /** Seek to a certain _position in the_item. **/
108                override public function seek(pos:Number):void {
[642]109                        clearInterval(_postitionInterval);
[364]110                        _position = pos;
111                        play();
112                }
[642]113
114
115                /** Stop the image _postitionInterval. **/
[364]116                override public function stop():void {
[642]117                        if (_loader.contentLoaderInfo.bytesLoaded != _loader.contentLoaderInfo.bytesTotal) {
118                                _loader.close();
[364]119                        } else {
[642]120                                _loader.unload();
[364]121                        }
[642]122                        clearInterval(_postitionInterval);
[364]123                        super.stop();
124                }
125        }
126}
Note: See TracBrowser for help on using the repository browser.