在ActionScript 2中播放FLV

时间:2009-11-24 02:12:01

标签: flash actionscript-2 flv haxe

我是Flash和Actionscript的新手。我想简单地播放一个FLV文件。我有以下内容:

import flash.MovieClip;
import flash.Video;
import flash.NetConnection;
import flash.NetStream;


class Program {
private var container_mc : MovieClip;
private var video_mc : Video;


public function new() {


   var mc : flash.MovieClip = flash.Lib.current;

          container_mc =  flash.Lib._root.attachMovie("VideoContainer", "container_mc", 0);

          container_mc.attachMovie("VideoClip", "video_mc", 1);

    var my_nc:NetConnection = new NetConnection();

    my_nc.connect(null);

    trace(my_nc.isConnected);

    var my_ns:NetStream = new NetStream(my_nc);

    //my_ns.setBufferTime(1);



    container_mc.video_mc.attachVideo(my_ns);

    my_ns.play("default.flv"); 

    trace("Done"); 
}
 public static function main()
 {
     new Program();
 }
}

我收到“完成”跟踪消息,但没有视频播放。我简单地在浏览器窗口中有一个黑盒子。有人可以帮我吗?万分感谢!

-Nick

3 个答案:

答案 0 :(得分:1)

您应仔细检查以确保库中有两个动画片段,其中包含您尝试附加的链接ID。

你需要两个:

VideoContainer
VideoClip

答案 1 :(得分:0)

new是关键字,因此您不能将其用作函数名称!!

答案 2 :(得分:-1)

我希望......下面的代码......会......工作得很好......

我使用fallowing .. preBuildCommand ..进入我的项目.. FAG EXPLORER FLV.fdp

<preBuildCommand>"$(ToolsDir)\swfmill\swfmill.exe" simple "library/video.xml" 

“库/ video.swf”

继续

FAG =免费学术游戏

当我使用

行时
<preBuildCommand>"$(ToolsDir)\swfmill\swfmill.exe" simple "library/video.xml" 

“库/ video.swf”

然后

项目必须包含以下行

<library>
    <asset path="Library\video.swf" />
</library>

观察:

swfmill.exe ..创建..文件.. video.swf ..进入目录..库

(库.. ..放在项目文件旁边)

swfmill.exe使用文件.. video.xml ..来创建..文件.. video.swf

文件的代码.. video.swf ..是

<?xml version="1.0" encoding="utf-8" ?>
<movie version="7">
<frame>
    <library>
        <clip id="VideoDisplay">
            <frame>
                <video id="VideoSurface" width="854" height="480"/>
                <place id="VideoSurface" name="video"/>
            </frame>
        </clip>
    </library>
</frame>
</movie>

继续

import util.VideoDisplay;

class util.Instances
{
function Instances() {

 //  _root.Fdisplay_MC

     _root.createEmptyMovieClip ("Fdisplay_MC", _root.getNextHighestDepth());

     _root.Fdisplay_MC._alpha = 50;

//
 var

 Fdisplay:VideoDisplay = new VideoDisplay(null, _root.Fdisplay_MC, "Fdisplay", 1);

_root.Fdisplay = Fdisplay; _root.Fdisplay._x = 5; _root.Fdisplay._y = 0;

    _root.Fdisplay.setVolume(100);

//
_root.Fdisplay_MC.onPress = function()

{
  if (_root.b_pause) _root.b_pause = 0 else _root.b_pause = 1;

     _root.Fdisplay.pause();

}// _root.Fdisplay_MC.onPress = function()

}// function Instances() {

}// class util.Instances

To be continued

/ ** *初始代码来自http://www.flashdevelop.org/community/viewtopic.php?t=321 *第3部分:流媒体FLV视频(仅限FlashDevelop / SWFMILL)

    I put the fallowing code into the initial class util.VideoDisplay  


// attach audio
display.attachAudio(ns);    

audio_sound = new Sound(display);


/**
* Get time in video
*/

public function pos():Number

{
    return ns.time;
}


public function setVolume(vol:Number):Void

{               
    audio_sound.setVolume(vol);
}

private var audio_sound:Sound;  

* /

class util.VideoDisplay
{
//{ PUBLIC MEMBERS

/**
* 
* Create a new video display surface
*/

function VideoDisplay(targetURI:String, parent:MovieClip, name:String, depth:Number, initObj)

{           
    display = parent.attachMovie("VideoDisplay", name, depth, initObj);

    // create video stream

    nc = new NetConnection();
    nc.connect(targetURI);

    ns = new NetStream(nc);

    // attach the video stream to the video object
    display.video.attachVideo(ns);

    // attach audio
    display.attachAudio(ns);    

    audio_sound = new Sound(display);       

} // VideoDisplay(targetURI:String, parent:MovieClip, name:String, depth:Number, initObj)


/**
* Video surface dimensions
*/
function setSize(width:Number, heigth:Number):Void
{
    display.video._width = width;
    display.video._height = heigth;
}
/**
* Video clip position
*/
function setLocation(x:Number, y:Number):Void
{
    display._x = x;
    display._y = y;
}

/**
* Start streaming
* @param    url FLV file
* @param    bufferTime  Buffer size (optional) 
*/
public function play(url:String, bufferTime:Number):Void
{
    if (bufferTime != undefined) ns.setBufferTime(bufferTime);
    ns.play(url);
}
/**
* Pause streaming
*/
public function pause():Void
{
    ns.pause();
}
/**
* Seek position in video
*/
public function seek(offset:Number):Void
{
    ns.seek(offset);
}   

/**
* Get time in video
*/

public function pos():Number

{
    return ns.time;
}

/**
* Close the video
*/

public function close():Void

{
    ns.close();
}   

    public function setVolume(vol:Number):Void

{               
    audio_sound.setVolume(vol);
}

//}

//{ PRIVATE MEMBERS 

private var display:MovieClip;
private var nc:NetConnection;
private var ns:NetStream;

private var audio_sound:Sound;  

//}

}