flashiroha

(92) FLVPlaybackカスタマイズによる動画プレイヤー(VIDEO PLAYER)(as3.0&2.0)
   −複数動画の順送り機能付き−      2009/9/14

as3.0
as2.0

import fl.video.*;
//
videoファイル名と題名を配列で定義
var videoSource:Array = new Array("video1.flv","video2.flv","video3.flv",
"video4.flv","video5.flv","video6.flv","video7.flv");
var videoTitle:Array = new Array("お神輿1","お神輿2","お神輿3","お神輿4",
"お神輿5","お囃子1","お囃子2");
//
video総数、初期再生させるvideo番号、直前に再生されたvideoのファイル名取得変数
var videoTotal:Number = videoSource.length;
var videoNumber:Number = 1;
var playedVideo:String;

//Video Player の初期設定
myPlayer.autoPlay = false;
myPlayer.source = "video/"+ videoSource[videoNumber-1];
myPlayer.playPauseButton = playpauseBtn;
myPlayer.seekBar = skBar;
myPlayer.muteButton = muteBtn;
myPlayer.volumeBar = volBar;
myPlayer.volume = 0.5;

//ボタン類の初期設定
replayBtn.visible = fdBtn.visible = bdBtn.visible = false;
playBtn.buttonMode = replayBtn.buttonMode = true;
fdBtn.buttonMode = bdBtn.buttonMode = true;
titleBox.buttonMode = true;

//ビデオ題名表示ボックス
titleBox.visible = false;

//再生イベントのリスニングと処置
function inPlay(event:VideoEvent):void {
  playBtn.visible = false;
  replayBtn.visible = fdBtn.visible = bdBtn.visible = false;
  myPlayer.alpha = 1;
  titleBox.visible = false;
}
myPlayer.addEventListener("playingStateEntered", inPlay);
function atEnd(event:VideoEvent):void {
  replayBtn.visible = fdBtn.visible = bdBtn.visible = true;
  myPlayer.alpha = 0.6;
  playedVideo = myPlayer.source;
}
myPlayer.addEventListener("complete", atEnd);

//ボタン類イベントのリスニングと処置
//
playBtn、replayBtn
function playStart(event:MouseEvent) {
  myPlayer.playWhenEnoughDownloaded();
}
playBtn.addEventListener( MouseEvent.CLICK, playStart);
function replayStart(event:MouseEvent) {
  myPlayer.source = playedVideo;
  myPlayer.playWhenEnoughDownloaded();
}
replayBtn.addEventListener( MouseEvent.CLICK, replayStart);
//
fowardBtn、backwardBtn
function displayNextSource(event:MouseEvent) {
  if (videoNumber>=videoTotal) {
    videoNumber=1;
  } else {
    videoNumber++;
  }
  titleBox.visible = true;
  titleBox.textField.text = videoTitle[videoNumber-1];
  myPlayer.source = "video/"+ videoSource[videoNumber-1];
}
fdBtn.addEventListener(MouseEvent.CLICK,displayNextSource);

function displayPreviousSource(event:MouseEvent) {
  if (videoNumber<=1) {
    videoNumber=videoTotal;
  } else {
    videoNumber--;
  }
  titleBox.visible = true;
  titleBox.textField.text = videoTitle[videoNumber-1];
  myPlayer.source = "video/"+ videoSource[videoNumber-1];
}
bdBtn.addEventListener(MouseEvent.CLICK,displayPreviousSource);

//題名表示フィールドイベントのリスニングと処置
function videoPlay(event:MouseEvent) {
  myPlayer.playWhenEnoughDownloaded();
}
titleBox.addEventListener(MouseEvent.CLICK,videoPlay);


import mx.video.*;

var videoSource:Array = new Array("video1.flv","video2.flv","video3.flv",
"video4.flv","video5.flv","video6.flv","video7.flv");
var videoTitle:Array = new Array("お神輿1","お神輿2","お神輿3",
"お神輿4","お神輿5","お囃子1","お囃子2");

var videoTotal:Number = videoSource.length;
var videoNumber:Number = 1;
var playedVideo:String;


myPlayer.autoPlay = false;
myPlayer.contentPath = "video/"+ videoSource[videoNumber-1];
myPlayer.playPauseButton = playpauseBtn;
myPlayer.seekBar = skBar;
myPlayer.muteButton = muteBtn;
myPlayer.volumeBar = volBar;
myPlayer.volume = 50;


replayBtn._visible = fdBtn._visible = bdBtn._visible = false;




titleBox._visible = false;


function inPlay(event:Object):Void {
  playBtn._visible = false;
  replayBtn._visible = fdBtn._visible = bdBtn._visible = false;
  myPlayer._alpha = 100;
  titleBox._visible = false;
}
myPlayer.addEventListener("playing", inPlay);
function atEnd(event:Object):Void {
  replayBtn._visible = fdBtn._visible = bdBtn._visible = true;
  myPlayer._alpha = 60;
  playedVideo = myPlayer.contentPath;
}
myPlayer.addEventListener("complete", atEnd);



playBtn.onRelease = function() {
  myPlayer.play();
}
replayBtn.onRelease = function() {
  myPlayer.contentPath = playedVideo;
  myPlayer.play();
}




fdBtn.onRelease = function() {
  if (videoNumber>=videoTotal) {
    videoNumber=1;
  } else {
    videoNumber++;
  }
  titleBox._visible = true;
  titleBox.textField.text = videoTitle[videoNumber-1];
  myPlayer.contentPath = "video/"+ videoSource[videoNumber-1];
}


bdBtn.onRelease = function() {
  if (videoNumber<=1) {
    videoNumber=videoTotal;
  } else {
    videoNumber--;
  }
  titleBox._visible = true;
  titleBox.textField.text = videoTitle[videoNumber-1];
  myPlayer.contentPath = "video/"+ videoSource[videoNumber-1];
}



titleBox.onRelease = function() {
  myPlayer.play();
}

 

スクリプトの若干の説明:
myPlayer.playPauseButton = playpauseBtn;
 配置したインスタンスplaypauseBtnをmyPlayer(FLVPlaybackのインスタンス)のPlayPauseButtonと関連付ける。(他のボタン、バー類も同様)
myPlayer.source = "video/"+ videoSource[videoNumber-1];
 再生ファイルの指定で、videoフォルダ内のビデオ番号から1を引いた番号の配列で指定したファイル名
myPlayer.addEventListener("playingStateEntered", inPlay);
 myPlayerの再生が開始状態になるのを認知したら関数inPlayを実施(as2.0では"playing")。
myPlayer.addEventListener("complete", atEnd);
 myPlayerの再生が完了したら関数atEndを実施。
fdBtn.addEventListener(MouseEvent.CLICK,displayNextSource);
 fdBtnがクリックされたら関数displayNextSourceを実施

なお、ページが開かれたら再生状態で始まるようにするには、
myPlayer.autoPlay = true; playBtn.visible = faulse;
 
とすれば良い(as2.0では_visible)。

また、初期にミュート状態で始めたい場合には、
as3.0: muteBtn.on_mc.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
as2.0: myPlayer.volume = "0"; myPlayer._uiMgr._isMuted = true;
とすればよい。

 
flashirohaサイト内  Web全体