Advertisement
Guest User

Простейший OSMF-плеер

a guest
Jan 18th, 2011
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.Sprite;
  4.     import flash.events.MouseEvent;
  5.    
  6.     import org.osmf.events.MediaFactoryEvent;
  7.     import org.osmf.media.DefaultMediaFactory;
  8.     import org.osmf.media.MediaElement;
  9.     import org.osmf.media.MediaFactory;
  10.     import org.osmf.media.MediaPlayerSprite;
  11.     import org.osmf.media.PluginInfoResource;
  12.     import org.osmf.media.URLResource;
  13.     import org.osmf.traits.AudioTrait;
  14.     import org.osmf.traits.MediaTraitType;
  15.     import ru.denivip.stats.StatsPluginInfo;
  16.    
  17.     [SWF(width="640", height="352")]
  18.     public class Main extends Sprite
  19.     {
  20.         protected var factory:MediaFactory;
  21.        
  22.         protected var sprite:MediaPlayerSprite;
  23.        
  24.         public function Main()
  25.         {
  26.             sprite = new MediaPlayerSprite();
  27.             addChild(sprite);
  28.            
  29.             factory = new DefaultMediaFactory();
  30.             factory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD, onPluginLoad);
  31.             factory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD_ERROR, onPluginLoadError);
  32.             factory.loadPlugin(new PluginInfoResource(new StatsPluginInfo()));
  33.         }
  34.        
  35.         private function onPluginLoad(event:MediaFactoryEvent):void
  36.         {
  37.             var media:MediaElement = factory.createMediaElement(new URLResource("http://openx.denivip.ru/test-portal/video/omlet.f4v"));
  38.             sprite.mediaPlayer.media = media;
  39.             sprite.addEventListener(MouseEvent.CLICK, onMouseClick);
  40.            
  41.             (media.getTrait(MediaTraitType.AUDIO) as AudioTrait).volume = 0.1;
  42.         }
  43.        
  44.         private function onPluginLoadError(event:MediaFactoryEvent):void
  45.         {
  46.             trace('plugin load error');
  47.         }
  48.  
  49.         private function onMouseClick(e:MouseEvent):void
  50.         {
  51.             trace('clicked');
  52.             if (sprite.mediaPlayer.playing) {
  53.                 sprite.mediaPlayer.pause();
  54.             }
  55.             else {
  56.                 sprite.mediaPlayer.play();
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement