Created
May 27, 2014 08:16
-
-
Save qhwa/87c7da68cd474c02bad9 to your computer and use it in GitHub Desktop.
VAST SDK Usage Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Basic AS3 VAST OVA Video Player Example | |
| * Released as open source under the BSD License | |
| * http://www.opensource.org/licenses/bsd-license.php | |
| * | |
| * hua.qiuh copied from dehash.com | |
| */ | |
| package { | |
| import com.apdevblog.events.video.VideoControlsEvent; | |
| import com.apdevblog.ui.video.ApdevVideoPlayer; | |
| import flash.display.Sprite; | |
| import flash.events.Event; | |
| import flash.system.Security; | |
| import org.openvideoads.vast.config.Config; | |
| import org.openvideoads.vast.config.ConfigLoadListener; | |
| import org.openvideoads.vast.playlist.DefaultPlaylist; | |
| import org.openvideoads.vast.playlist.PlaylistItem; | |
| import org.openvideoads.vast.server.events.TemplateEvent; | |
| import org.openvideoads.vast.VASTController; | |
| public class Main extends Sprite { | |
| private var vastController:VASTController; | |
| private var videoPlayer:ApdevVideoPlayer; | |
| private var myPlaylist:DefaultPlaylist; | |
| private var rawConfigLocal:Config; | |
| public function Main():void { | |
| if (stage) { | |
| init(); | |
| } else { | |
| addEventListener(Event.ADDED_TO_STAGE, init); | |
| } | |
| } | |
| private function init(e:Event = null):void { | |
| initStage(); | |
| initVideoPlayer(); | |
| initSecurity(); | |
| initAd(); | |
| } | |
| private function initStage():void { | |
| stage.align = 'left'; | |
| stage.scaleMode = 'noScale'; | |
| removeEventListener(Event.ADDED_TO_STAGE, init); | |
| } | |
| private function initVideoPlayer():void { | |
| videoPlayer = new ApdevVideoPlayer(400, 300); | |
| videoPlayer.addEventListener(VideoControlsEvent.STATE_UPDATE, onStateUpdate, false, 0, true); | |
| videoPlayer.autoPlay = true; | |
| addChild(videoPlayer); | |
| } | |
| private function initSecurity():void { | |
| Security.allowDomain("*"); | |
| } | |
| private function initAd():void { | |
| var demoContentStream:String = "bunny.flv"; | |
| var demoTag:String = 'vast-v3.xml'; | |
| rawConfigLocal = new Config({ | |
| debug: { | |
| levels: "fatal, config, vast_template" | |
| }, | |
| shows: { | |
| streams: [ | |
| { | |
| file: demoContentStream, | |
| duration: "30" | |
| } | |
| ] | |
| }, | |
| ads: { | |
| schedule: [ | |
| { | |
| position: "pre-roll", | |
| tag: demoTag | |
| } | |
| ] | |
| } | |
| }); | |
| vastController = new VASTController(); | |
| vastController.addEventListener(TemplateEvent.LOADED, onTemplateLoaded); | |
| vastController.startStreamSafetyMargin = 500; | |
| vastController.endStreamSafetyMargin = 500; | |
| vastController.initialise(rawConfigLocal, true); | |
| } | |
| /** | |
| * VAST 数据加载完成,把广告加入播放列表,开始展示 | |
| */ | |
| private function onTemplateLoaded(e:TemplateEvent):void { | |
| myPlaylist = new DefaultPlaylist( | |
| vastController.streamSequence, | |
| vastController.config.showsConfig.providersConfig, | |
| vastController.config.adsConfig.providersConfig | |
| ); | |
| showNextVideo() | |
| } | |
| private function showNextVideo():void { | |
| var p:PlaylistItem = myPlaylist.nextTrackAsPlaylistItem(); | |
| videoPlayer.load( p.url ); | |
| } | |
| /** | |
| * 自动播放下一个视频 | |
| */ | |
| private function onStateUpdate(e:VideoControlsEvent):void { | |
| if (e.data == 'videoStateStopped') { | |
| if (myPlaylist.currentTrackIndex <myPlaylist.length) { | |
| showNextVideo() | |
| } else { | |
| //全部播放完成 | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment