视频swf通过php和actionscript从mysql数据库加载文件

发布于 2024-10-26 03:21:57 字数 3772 浏览 2 评论 0原文

我正在尝试创建一个视频,将视频加载到目录中,取决于用户 ID 等。

为此,我使用 php。但是,我无法在操作脚本中将 php 转换为 xml:

这是 php 代码:

$query = "SELECT * FROM video_files ORDER BY video_id DESC"; 
$resultID = mysql_query($query) or die("Data not found."); 

$xml_output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; 
$xml_output .= "<PLAYLIST VIDEO_X=\"0\" VIDEO_Y=\"0\" >\n"; 

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ 
    $row = mysql_fetch_assoc($resultID); 
    $xml_output .= "<VIDEO TITLE=\"".$row['title']."\" THUMB=\"\" URL=\"".$row['path']."\"/>\n"; 
} 

$xml_output .= "</PLAYLIST>"; 

echo $xml_output;

这是操作脚本:

import fl.video.*;

var thumb_width:Number;
var thumb_height:Number;
var thumbs_x:Number;
var thumbs_y:Number;
var video_x:Number;
var video_y:Number;
var my_videos:XMLList;
var my_total:Number;

var main_container:Sprite;
var thumbs:Sprite;
var titles:Sprite;
var my_player:FLVPlayback;

var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load (new URLRequest("playlist.php"));
myXMLLoader.addEventListener (Event.COMPLETE, processXML);

function processXML (e:Event):void {
    var myXML:XML = new XML(e.target.data);

    thumb_width = myXML.@THUMB_WIDTH;
    thumb_height = myXML.@THUMB_HEIGHT;
    thumbs_x = myXML.@THUMBS_X;
    thumbs_y = myXML.@THUMBS_Y;
    video_x = myXML.@VIDEO_X;
    video_y = myXML.@VIDEO_Y;
    my_videos = myXML.VIDEO;
    my_total = my_videos.length();

    makeContainers ();
    callThumbs ();
    makePlayer ();
}

function makeContainers ():void {
    main_container = new Sprite();
    addChild (main_container);

    thumbs = new Sprite();
    thumbs.addEventListener (MouseEvent.CLICK, playVideo);
    thumbs.addEventListener (MouseEvent.MOUSE_OVER, onOver);
    thumbs.addEventListener (MouseEvent.MOUSE_OUT, onOut);
    thumbs.x = thumbs_x;
    thumbs.y = thumbs_y;
    thumbs.buttonMode = true;
    main_container.addChild (thumbs);

    titles = new Sprite();
    titles.x = thumbs_x;
    titles.y = thumbs_y;
    main_container.addChild (titles);
}

function callThumbs ():void {
    for (var i:Number = 0; i < my_total; i++) {

        var thumb_url = my_videos[i].@THUMB;
        var thumb_loader = new Loader();
        thumb_loader.name = i;
        thumb_loader.load (new URLRequest(thumb_url));
        thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);
        thumb_loader.y = (thumb_height+10)*i;

        var thumb_title = my_videos[i].@TITLE;
        var title_txt:TextField = new TextField();
        title_txt.text = thumb_title;
        title_txt.y = thumb_loader.y;
        title_txt.x = thumb_width + 10;
        title_txt.width = thumb_width;
        title_txt.height = thumb_height;
        title_txt.wordWrap = true;
        titles.addChild (title_txt);


    }
}

function thumbLoaded (e:Event):void {
    var my_thumb:Loader = Loader(e.target.loader);
    thumbs.addChild (my_thumb);
}

function makePlayer ():void {
    my_player = new FLVPlayback();
    my_player.skin ="videos/videoskin.swf";
    my_player.skinBackgroundColor = 0xAEBEFB;
    my_player.skinBackgroundAlpha = 0.9;

    my_player.x = video_x;
    my_player.y = video_y;
    my_player.width = 500;
    my_player.height = 400;

    main_container.addChild (my_player);
    my_player.source = my_videos[0].@URL;
}

function playVideo (e:MouseEvent):void {
    var video_url = my_videos[e.target.name].@URL;
    my_player.source = video_url;
}

function onOver (e:MouseEvent):void {
    var my_thumb:Loader = Loader(e.target);
    my_thumb.alpha = 0.5;
}
function onOut (e:MouseEvent):void {
    var my_thumb:Loader = Loader (e.target);
    my_thumb.alpha = 1;
}

有人知道我哪里出错了吗?它适用于普通的 xml 文件,但不适用于 php

I am trying to create a video that loads the videos stred in a directory, depenant on the users id etc.

To do this, I am using php. However, I cannot then get the php to convert to xml within the actionscript:

Here is php code:

$query = "SELECT * FROM video_files ORDER BY video_id DESC"; 
$resultID = mysql_query($query) or die("Data not found."); 

$xml_output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; 
$xml_output .= "<PLAYLIST VIDEO_X=\"0\" VIDEO_Y=\"0\" >\n"; 

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ 
    $row = mysql_fetch_assoc($resultID); 
    $xml_output .= "<VIDEO TITLE=\"".$row['title']."\" THUMB=\"\" URL=\"".$row['path']."\"/>\n"; 
} 

$xml_output .= "</PLAYLIST>"; 

echo $xml_output;

here is actionscript:

import fl.video.*;

var thumb_width:Number;
var thumb_height:Number;
var thumbs_x:Number;
var thumbs_y:Number;
var video_x:Number;
var video_y:Number;
var my_videos:XMLList;
var my_total:Number;

var main_container:Sprite;
var thumbs:Sprite;
var titles:Sprite;
var my_player:FLVPlayback;

var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load (new URLRequest("playlist.php"));
myXMLLoader.addEventListener (Event.COMPLETE, processXML);

function processXML (e:Event):void {
    var myXML:XML = new XML(e.target.data);

    thumb_width = myXML.@THUMB_WIDTH;
    thumb_height = myXML.@THUMB_HEIGHT;
    thumbs_x = myXML.@THUMBS_X;
    thumbs_y = myXML.@THUMBS_Y;
    video_x = myXML.@VIDEO_X;
    video_y = myXML.@VIDEO_Y;
    my_videos = myXML.VIDEO;
    my_total = my_videos.length();

    makeContainers ();
    callThumbs ();
    makePlayer ();
}

function makeContainers ():void {
    main_container = new Sprite();
    addChild (main_container);

    thumbs = new Sprite();
    thumbs.addEventListener (MouseEvent.CLICK, playVideo);
    thumbs.addEventListener (MouseEvent.MOUSE_OVER, onOver);
    thumbs.addEventListener (MouseEvent.MOUSE_OUT, onOut);
    thumbs.x = thumbs_x;
    thumbs.y = thumbs_y;
    thumbs.buttonMode = true;
    main_container.addChild (thumbs);

    titles = new Sprite();
    titles.x = thumbs_x;
    titles.y = thumbs_y;
    main_container.addChild (titles);
}

function callThumbs ():void {
    for (var i:Number = 0; i < my_total; i++) {

        var thumb_url = my_videos[i].@THUMB;
        var thumb_loader = new Loader();
        thumb_loader.name = i;
        thumb_loader.load (new URLRequest(thumb_url));
        thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);
        thumb_loader.y = (thumb_height+10)*i;

        var thumb_title = my_videos[i].@TITLE;
        var title_txt:TextField = new TextField();
        title_txt.text = thumb_title;
        title_txt.y = thumb_loader.y;
        title_txt.x = thumb_width + 10;
        title_txt.width = thumb_width;
        title_txt.height = thumb_height;
        title_txt.wordWrap = true;
        titles.addChild (title_txt);


    }
}

function thumbLoaded (e:Event):void {
    var my_thumb:Loader = Loader(e.target.loader);
    thumbs.addChild (my_thumb);
}

function makePlayer ():void {
    my_player = new FLVPlayback();
    my_player.skin ="videos/videoskin.swf";
    my_player.skinBackgroundColor = 0xAEBEFB;
    my_player.skinBackgroundAlpha = 0.9;

    my_player.x = video_x;
    my_player.y = video_y;
    my_player.width = 500;
    my_player.height = 400;

    main_container.addChild (my_player);
    my_player.source = my_videos[0].@URL;
}

function playVideo (e:MouseEvent):void {
    var video_url = my_videos[e.target.name].@URL;
    my_player.source = video_url;
}

function onOver (e:MouseEvent):void {
    var my_thumb:Loader = Loader(e.target);
    my_thumb.alpha = 0.5;
}
function onOut (e:MouseEvent):void {
    var my_thumb:Loader = Loader (e.target);
    my_thumb.alpha = 1;
}

anyone know where i am going wrong? It works with a normal xml file just not php

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

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

发布评论

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

评论(1

怎会甘心 2024-11-02 03:21:57

PHP 中的 XML 输出格式错误。每个标签都必须关闭。

您有:

<?xml version="1.0" encoding="utf-8"?>
<PLAYLIST VIDEO_X="0" VIDEO_Y="0">
<VIDEO TITLE="videotitle" THUMB="thumbnail" URL="URL" />
</PLAYLIST>

您需要关闭视频标签。因此输出应如下所示:

<?xml version="1.0" encoding="utf-8"?>
<PLAYLIST VIDEO_X="0" VIDEO_Y="0">
<VIDEO TITLE="videotitle" THUMB="thumbnail" URL="URL"></VIDEO>
</PLAYLIST>

您还应该为 PHP 脚本设置内容类型。

header('Content-type: text/xml');  

我无法使用我的笔记本电脑来彻底测试您的代码,但这是我第一眼看到您的代码时的答案。

The format for your XML output in PHP is wrong. Every tag must be closed.

You have:

<?xml version="1.0" encoding="utf-8"?>
<PLAYLIST VIDEO_X="0" VIDEO_Y="0">
<VIDEO TITLE="videotitle" THUMB="thumbnail" URL="URL" />
</PLAYLIST>

You need to close the video tag. So output should look like this:

<?xml version="1.0" encoding="utf-8"?>
<PLAYLIST VIDEO_X="0" VIDEO_Y="0">
<VIDEO TITLE="videotitle" THUMB="thumbnail" URL="URL"></VIDEO>
</PLAYLIST>

You should also set the content-type for your PHP script.

header('Content-type: text/xml');  

I don't have access to my laptop to thoroughly test your code, but this is my answer from a first glance at your code.

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