在 ActionScript 2 中播放 FLV

发布于 2024-08-12 09:04:30 字数 928 浏览 8 评论 0原文

我对 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();
 }
}

我收到“完成”跟踪消息,但没有视频播放。我只是在浏览器窗口中有一个黑框。有人可以帮我吗?非常感谢!

-缺口

I am very new to Flash and Actionscript. I am trying to simply play an FLV file. I have the following:

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();
 }
}

I get the "Done" trace message back but no video playback. I simple have a black box in the browser window. Can someone help me out? Thanks a ton!

-Nick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里梦着梦中梦 2024-08-19 09:04:30

您应该仔细检查以确保库中有两个影片剪辑具有您要附加的链接 ID。

您将需要两者:

VideoContainer
VideoClip

You should double check to make sure you have two movieclips in the library that have the linkage IDs that you're trying to attach.

You'll need both:

VideoContainer
VideoClip
屋顶上的小猫咪 2024-08-19 09:04:30

new 是一个关键字,所以你不能将它用作函数名!

new is a keyword, so you can't use it as a function name!!

把昨日还给我 2024-08-19 09:04:30

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

我使用下面的..preBuildCommand..到我的项目中..FAG EXPLORER FLV.fdp

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

“library/video.swf”

待续

FAG = FREE学术游戏

行时

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

当我使用“library/video.swf”

项目必须包含以下行

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

观察:

swfmill.exe .. 创建 .. 文件 .. video.swf .. 到目录 .. Library

(library . .. 放置在项目文件旁边)

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;  

//}

}

I hope that .. the code bellow .. will .. work very well ..

I use the fallowing .. preBuildCommand .. into my project .. FAG EXPLORER FLV.fdp

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

"library/video.swf"

To be continued

FAG = FREE ACADEMIC GAMES

When I use the line

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

"library/video.swf"

then

the project must contain the lines below

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

Observations:

swfmill.exe .. creates .. the file .. video.swf .. into the directory .. library

(library .. is .. placed next to the project file)

swfmill.exe uses the file .. video.xml .. to create .. the file .. video.swf

The code of the file .. video.swf .. is

<?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>

To be continued

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

/**
* The initial code is from http://www.flashdevelop.org/community/viewtopic.php?t=321
* Part 3. Streaming FLV videos (FlashDevelop/SWFMILL only)

    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;  

//}

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文