问题
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
回答1:
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
回答2:
new is a keyword, so you can't use it as a function name!!
回答3:
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;
//}
}
来源:https://stackoverflow.com/questions/1787360/play-flv-in-actionscript-2