| <?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initData();"
nativeDragEnter="Check_DragEnter(event)"
nativeDragDrop="Check_DropFile(event)"
usePreloader="true"
titleIcon="{imgSmile}"
title="エクスプローラから flv をドラッグ・ドロップできます"
headerHeight="80"
cornerRadius="20"
titleTextStyleName="titleStyle"
>
<mx:Style>
WindowedApplication {
backgroundGradientColors: 0,9044009;
}
.titleStyle {
fontSize: 12;
}
Alert {
backgroundColor: #FFFFFF;
backgroundAlpha: 1;
color: #000000;
borderColor: #000000;
borderStyle: solid;
borderThickness: 1;
headerColors: #A0A0A0,#A0A0A0;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.*;
import mx.events.*;
import flash.filesystem.*;
import flash.events.Event;
[Bindable]
[Embed("smile.png")]
private static var imgSmile:Class;
private var nSize:int = 1;
private var rootObject:WindowedApplication;
private var nativeMenu:ContextMenu;
// *********************************************************
// アプリケーションの初期化
// *********************************************************
public function initData():void {
// メッセージ
trace( "initData() が実行されました" );
// 再生イベントの発生間隔
myVid.playheadUpdateInterval = 1;
// プログレスバーの初期化
progressBar.setProgress(0, 100);
// Mainw.xml の値を変更
this.height = 600;
// 初期ボリューム
myVid.volume = 0.7;
// *************************************************
// コンテキストメニュー定義
// *************************************************
rootObject = WindowedApplication(mx.core.Application.application)
nativeMenu = new ContextMenu();
nativeMenu.hideBuiltInItems();
addContextMenu(
"x 1",
function():void {
changeSize(1);
}
);
addContextMenu(
"x 2",
function():void {
changeSize(2);
}
);
addContextMenu(
"x 0.5",
function():void {
changeSize(3);
}
);
addContextMenu(
"ベースを最大化",
function():void {
myVid.stage.displayState = 'fullScreen';
}
);
addContextMenu(
"ベースを標準",
function():void {
myVid.stage.displayState = 'normal';
}
);
rootObject.contextMenu = nativeMenu;
}
// *********************************************************
// コンテキストメニュー追加
// *********************************************************
public function addContextMenu(
label:String,
listener:Function
):void {
var menuItem:ContextMenuItem;
menuItem = new ContextMenuItem(label);
menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,listener);
nativeMenu.customItems.push(menuItem);
}
// *********************************************************
// 外部からドラッグ開始
// *********************************************************
private function Check_DragEnter(e:NativeDragEvent):void {
var clip:Clipboard = e.clipboard;
if ( clip.hasFormat( ClipboardFormats.FILE_LIST_FORMAT ) ) {
NativeDragManager.acceptDragDrop(this);
}
}
// *********************************************************
// 外部からドロップ
// *********************************************************
private function Check_DropFile(e:NativeDragEvent):void {
var clip:Clipboard = e.clipboard;
var file_list:Array;
file_list = clip.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
var str:String = file_list[0].nativePath;
var part:Array = str.split(".");
var len:int = part.length;
var ext:String = (part[len-1]).toUpperCase();
if ( ext == "MP4" || ext == "FLV" ) {
myVid.source = file_list[0].nativePath;
myVid.load();
progressBar.setProgress(0, 100);
}
else {
Alert.show( "flv か mp4 を使用して下さい" );
}
}
// *********************************************************
// 再生ヘッド位置の表示
// *********************************************************
public function playhead_Update(e:mx.events.VideoEvent):void {
progressBar.setProgress(
e.playheadTime,
e.currentTarget.totalTime
);
}
// *********************************************************
// ストップ( リセット )処理
// *********************************************************
public function play_Reset():void {
// STOP ボタンを使用した場合は巻き戻すが、
// 最後まで表示した場合は巻き戻さない
myVid.autoRewind = true;
myVid.stop();
myVid.autoRewind = false;
}
// *********************************************************
// シーク
// *********************************************************
private function setTime( e:MouseEvent ):void {
myVid.playheadTime = ( e.localX * myVid.totalTime )/ progressBar.width;
}
// *********************************************************
// サイズ変更
// *********************************************************
private function changeSize( nSize:int ):void {
switch( nSize ) {
case 1:
myVid.width = myVid.videoWidth;
myVid.height = myVid.videoHeight;
break;
case 2:
myVid.width = myVid.videoWidth * 2;
myVid.height = myVid.videoHeight * 2;
break;
case 3:
myVid.width = myVid.videoWidth / 2;
myVid.height = myVid.videoHeight / 2;
break;
}
}
// *********************************************************
// スライダー変更イベント
// *********************************************************
private function changeVolume( ):void {
myVid.volume = hSlider.value;
}
]]>
</mx:Script>
<mx:Panel
title="超シンプル flv プレーヤー"
horizontalAlign="center"
paddingLeft="10"
paddingRight="10"
>
<mx:VideoDisplay
id="myVid"
autoPlay="false"
autoRewind="false"
playheadUpdate="playhead_Update(event)"
complete="progressBar.setProgress(100,100)"
source="sample.mp4"
ready="changeSize(1);"
/>
<mx:VBox width="100%">
<mx:HBox>
<mx:Button
label="Play"
click="myVid.play();"
width="60"
/>
<mx:Button
label="Pause"
click="myVid.pause();"
width="60"
/>
<mx:Button
label="Stop"
click="play_Reset();"
width="60"
/>
<mx:HSlider
id="hSlider"
minimum="0"
maximum="1"
value="0.7"
snapInterval="0.1"
change="changeVolume();"
/>
</mx:HBox>
<mx:ProgressBar
id="progressBar"
mode="manual"
label=""
width="100%"
click="setTime(event)"
/>
</mx:VBox>
</mx:Panel>
</mx:WindowedApplication>
| |