将视频控件添加到 XML 组合框选择的视频时遇到问题

发布于 2024-10-10 03:45:25 字数 5611 浏览 0 评论 0原文

我已经更接近我最终想要的结果了,谢谢。

剩下的两个问题是,当我点击上一个和下一个时,组合框中显示的名称有时会不同步。

而且我似乎无法让视频洗涤器工作。

查看实际操作

将 index.zip 添加到上面的 dl 源文件链接中(没有足够的点post 2 links)

import fl.data.DataProvider;
import flash.net.NetStream;

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var videosXML:XML = new XML();
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("xml/videos.xml");
var videos:Array = new Array({label:"Select a Video",data:""});
var client:Object = new Object();
var _currentVideoId:int = 0;
var _isPlaying:Boolean = false;
var stream:NetStream;
var videoURL:String;
var connection:NetConnection;
var videoInterval = setInterval(videoStatus,100);
var amountLoaded:Number;
var meta:Object = new Object();
var duration:Number;

// load the XML

loader.addEventListener(Event.COMPLETE,loaderOnComplete);
loader.load(request);

function loaderOnComplete(event:Event):void
{
    videosXML = new XML(event.target.data);
    for each (var video:XML in videosXML.video)
    {
        videos.push({label:video.name.toString(),data:video.url.toString()});
    }
    moviesCB.dataProvider = new DataProvider(videos);

    // load the first video
    initialize_video_player();
}

function initialize_video_player():void
{
    // loads first video in list
    videoURL = videosXML.video[0].url;
    connection = new NetConnection();
    connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    connection.connect(null);
    moviesCB.selectedIndex = _currentVideoId++;
}

function playerControls():void
{
    pauseBtn.addEventListener(MouseEvent.CLICK, PauseVideo, false, 0, true);
    playBtn.addEventListener(MouseEvent.CLICK, PlayVideo, false, 0, true);
    nextBtn.addEventListener(MouseEvent.CLICK, NextVideo);
    previousBtn.addEventListener(MouseEvent.CLICK, PreviousVideo);
}

function PauseVideo($e:MouseEvent):void
{
     stream.togglePause();
}

function PlayVideo($e:MouseEvent):void
{
    stream.resume();
}

function netStatusHandler(event:NetStatusEvent):void
{
    switch (event.info.code)
    {
        case "NetConnection.Connect.Success" :
        connectStream();
        break;
        case "NetStream.Play.StreamNotFound" :
        trace("Unable to locate video: " + videoURL);
        break;
    }
}

function connectStream():void
{
    stream = new NetStream(connection);
    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
    theVideo.attachNetStream(stream);
    playerControls();
}

function securityErrorHandler(event:SecurityErrorEvent):void
{
    trace("securityErrorHandler: " + event);
}

function asyncErrorHandler(event:AsyncErrorEvent):void
{
    // ignore AsyncErrorEvent events.
}

moviesCB.addEventListener(Event.CHANGE, changeHandler);

function changeHandler(event:Event):void
{
    if (ComboBox(event.target).selectedItem.data != "")
    {
        stream.play(ComboBox(event.target).selectedItem.data);
        _currentVideoId=moviesCB.selectedIndex;
        }
}

function NextVideo(e:MouseEvent):void
{
    if (_currentVideoId<videosXML.video.length()-1)
{
    _currentVideoId++;
    loadNewVideo();
}
else
{
    // do nothing, already at maximum videoId
}
}

function PreviousVideo(e:MouseEvent):void
{
    trace ("previous video with current video of "+_currentVideoId);
    if (_currentVideoId>0)
    {
        _currentVideoId--;
          loadNewVideo();
    }
    else
    {
    // do nothing, already at 0
    }
}

function loadNewVideo():void
{
// because it's not a mouse action, tell the stream what to play
stream.play(videosXML.video[_currentVideoId].url.toString());
// and update the selectedIndex of the ComboBox
moviesCB.selectedIndex=_currentVideoId;
}

function videoStatus()
{
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
videoLoader.loadBar._width = amountLoaded * 640;
}

meta.onMetaData = function(meta:Object)
{
trace(meta.duration);
}

ns.client = meta;

/////// 原帖 //////////////

你好,自从我接触闪光灯以来已经有几年了,所以也许我只是忽略了一些东西。如果有人可以查看代码并提供任何建议,那就太棒了。

工作原理是,我从由 XML 文件填充的组合框中选择一个视频,选择该视频并播放。

我一直在尝试添加暂停/播放、停止、前进和后退功能,一旦我开始工作,我还想添加一个视频洗涤器(滑块)和上一个/下一个按钮以转到上一个/下一个视频xml 文件中列出。

目前,我在舞台上有一个名为 playButton 的组件按钮,我试图将其用于暂停/播放功能。下面是我的代码,播放器控件位于最底部。谢谢。

import fl.data.DataProvider;

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var videosXML:XML = new XML();
var loader:URLLoader = new URLLoader();
var request:URLRequest= new URLRequest("xml/videos.xml");
var videos:Array = new Array({label:"Select a Video",data:""});
var client:Object = new Object();  

theVideo.attachNetStream(ns);
ns.client = client;
 loader.addEventListener(Event.COMPLETE,loaderOnComplete);
 loader.load (request);

function loaderOnComplete(event:Event):void{
    videosXML = new XML(event.target.data); 
    for each (var video:XML in videosXML.video){
        videos.push({label:video.name.toString(),data:video.url.toString()});
    }
    moviesCB.dataProvider = new DataProvider(videos);
}

moviesCB.addEventListener(Event.CHANGE, changeHandler);

function changeHandler(event:Event):void {
    if(ComboBox(event.target).selectedItem.data != ""){
        ns.play(ComboBox(event.target).selectedItem.data);
    }
};

client.onMetaData = metadataHandler;
function metadataHandler(md:Object):void{
}

//player controls
playButton.onRelease = function() {
    ns.pause();
}

I'm much closer to my final desired outcome, thank you.

Two remaining issues, when I hit previous and next, the name shown in the combobox sometimes gets out of sync.

Also I can't seem to get the video scrubber to work.

See it in action

add index.zip to the link above to dl source files (don't have enough points to post 2 links)

import fl.data.DataProvider;
import flash.net.NetStream;

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var videosXML:XML = new XML();
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("xml/videos.xml");
var videos:Array = new Array({label:"Select a Video",data:""});
var client:Object = new Object();
var _currentVideoId:int = 0;
var _isPlaying:Boolean = false;
var stream:NetStream;
var videoURL:String;
var connection:NetConnection;
var videoInterval = setInterval(videoStatus,100);
var amountLoaded:Number;
var meta:Object = new Object();
var duration:Number;

// load the XML

loader.addEventListener(Event.COMPLETE,loaderOnComplete);
loader.load(request);

function loaderOnComplete(event:Event):void
{
    videosXML = new XML(event.target.data);
    for each (var video:XML in videosXML.video)
    {
        videos.push({label:video.name.toString(),data:video.url.toString()});
    }
    moviesCB.dataProvider = new DataProvider(videos);

    // load the first video
    initialize_video_player();
}

function initialize_video_player():void
{
    // loads first video in list
    videoURL = videosXML.video[0].url;
    connection = new NetConnection();
    connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    connection.connect(null);
    moviesCB.selectedIndex = _currentVideoId++;
}

function playerControls():void
{
    pauseBtn.addEventListener(MouseEvent.CLICK, PauseVideo, false, 0, true);
    playBtn.addEventListener(MouseEvent.CLICK, PlayVideo, false, 0, true);
    nextBtn.addEventListener(MouseEvent.CLICK, NextVideo);
    previousBtn.addEventListener(MouseEvent.CLICK, PreviousVideo);
}

function PauseVideo($e:MouseEvent):void
{
     stream.togglePause();
}

function PlayVideo($e:MouseEvent):void
{
    stream.resume();
}

function netStatusHandler(event:NetStatusEvent):void
{
    switch (event.info.code)
    {
        case "NetConnection.Connect.Success" :
        connectStream();
        break;
        case "NetStream.Play.StreamNotFound" :
        trace("Unable to locate video: " + videoURL);
        break;
    }
}

function connectStream():void
{
    stream = new NetStream(connection);
    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
    theVideo.attachNetStream(stream);
    playerControls();
}

function securityErrorHandler(event:SecurityErrorEvent):void
{
    trace("securityErrorHandler: " + event);
}

function asyncErrorHandler(event:AsyncErrorEvent):void
{
    // ignore AsyncErrorEvent events.
}

moviesCB.addEventListener(Event.CHANGE, changeHandler);

function changeHandler(event:Event):void
{
    if (ComboBox(event.target).selectedItem.data != "")
    {
        stream.play(ComboBox(event.target).selectedItem.data);
        _currentVideoId=moviesCB.selectedIndex;
        }
}

function NextVideo(e:MouseEvent):void
{
    if (_currentVideoId<videosXML.video.length()-1)
{
    _currentVideoId++;
    loadNewVideo();
}
else
{
    // do nothing, already at maximum videoId
}
}

function PreviousVideo(e:MouseEvent):void
{
    trace ("previous video with current video of "+_currentVideoId);
    if (_currentVideoId>0)
    {
        _currentVideoId--;
          loadNewVideo();
    }
    else
    {
    // do nothing, already at 0
    }
}

function loadNewVideo():void
{
// because it's not a mouse action, tell the stream what to play
stream.play(videosXML.video[_currentVideoId].url.toString());
// and update the selectedIndex of the ComboBox
moviesCB.selectedIndex=_currentVideoId;
}

function videoStatus()
{
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
videoLoader.loadBar._width = amountLoaded * 640;
}

meta.onMetaData = function(meta:Object)
{
trace(meta.duration);
}

ns.client = meta;

/////// Original Post //////////////

Hello, it's been a few years since I've touched flash, so perhaps I'm just overlooking something. If anyone could look at the code and offer any suggestions that would be awesome.

What's working, I select a video from a combobox that is populated from an XML file, pick the video and it plays.

I've been trying to add pause/play, stop, forward and reverse functionality, once I get that to work I also want to add a video scrubber(slider), and previous/next buttons to go to the previous/next video as listed in the xml file.

At the moment I have a component button on the stage called playButton, which I'm trying to use for pause/play functionality. Below is my code, the player control is at the very bottom. Thanks.

import fl.data.DataProvider;

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var videosXML:XML = new XML();
var loader:URLLoader = new URLLoader();
var request:URLRequest= new URLRequest("xml/videos.xml");
var videos:Array = new Array({label:"Select a Video",data:""});
var client:Object = new Object();  

theVideo.attachNetStream(ns);
ns.client = client;
 loader.addEventListener(Event.COMPLETE,loaderOnComplete);
 loader.load (request);

function loaderOnComplete(event:Event):void{
    videosXML = new XML(event.target.data); 
    for each (var video:XML in videosXML.video){
        videos.push({label:video.name.toString(),data:video.url.toString()});
    }
    moviesCB.dataProvider = new DataProvider(videos);
}

moviesCB.addEventListener(Event.CHANGE, changeHandler);

function changeHandler(event:Event):void {
    if(ComboBox(event.target).selectedItem.data != ""){
        ns.play(ComboBox(event.target).selectedItem.data);
    }
};

client.onMetaData = metadataHandler;
function metadataHandler(md:Object):void{
}

//player controls
playButton.onRelease = function() {
    ns.pause();
}

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

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

发布评论

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

评论(2

剩余の解释 2024-10-17 03:45:25

我想你想这样做(点击处理程序在AS3中是不同的)

playButton.addEventListener(MouseEvent.CLICK, onTogglePlay);

function onTogglePlay(e:MouseEvent):void {
   ns.togglePause();
}

你应该在NC上为NetStatusEvent放置一个监听器,然后在连接连接后创建NetStream。

I think you want to do this (Click Handlers are different in AS3)

playButton.addEventListener(MouseEvent.CLICK, onTogglePlay);

function onTogglePlay(e:MouseEvent):void {
   ns.togglePause();
}

You should really put a listener on the NC for the NetStatusEvent and then create the NetStream once the connection is connected.

烟沫凡尘 2024-10-17 03:45:25

我原来问题的答案是使用stream.bytesTotal和stream.bytesLoaded而不是ns.bytesTotal和ns.bytesLoaded

The answer to my original question was to use stream.bytesTotal and stream.bytesLoaded instead of ns.bytesTotal and ns.bytesLoaded

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