自己制作FLV播放器

制作步骤:
  1.新建一个FLASH文档,设置舞台大小:300*260。
  2.将组件MediaController和MediaDisplay拖入舞台,然后从舞台上删除。这样做的目的是将这两个组件载入库中,为接下来用attachMovie()方法将MediaController和MediaDisplay组件载入舞台做好准备。


  3.新建一层,命名为function。在该层的第一帧上输入如下AS代码:
function init(){
flagNum = 1;
//播放影片的标示
flvNum = 0;
attachController();
};
//将MediaController和MediaDisplay组件载入舞台并初始化
function attachController(){
//将MediaDisplay组件载入舞台并给定义实例名 “flvContainer” + flagNum
_root.attachMovie(“MediaDisplay”,”flvContainer” + flagNum,2);
//设置组件初始参数
with(_root[“flvContainer” + flagNum]){
_x = 0;
_y = 0;
setMedia(myArray[flvNum],”FLV”);//设置播放格式可以mp3等
}
//将MediaController组件载入舞台并给定义实例名 “flvController” + flagNum
_root.attachMovie(“MediaController”,”flvController” + flagNum,1);
//设置组件初始参数
with(_root[“flvController” + flagNum]){
_x = 0;
_y = 190;
activePlayControl = false;
controllerPolicy = “on”;
//将MediaController和MediaDisplay组件相关联
associateDisplay(_root[“flvContainer” + flagNum]);
};
};
function playNext(){
//将MediaController和MediaDisplay组件从舞台上删除
_root[“flvController” + flagNum].removeMovieClip();
_root[“flvContainer” + flagNum].removeMovieClip();
flagNum += 1;
flvNum += 1;
//如果播放到影片的最后一首,将flvNum = 0,意为将从头开始播放
if(flvNum == flvTotal) flvNum = 0;
//重新载入MediaController和MediaDisplay组件,并给一新的实例名
attachController();
//因为每播放完一个影片后MediaController和MediaDisplay组件从舞台上被卸载
//然后又重新载入MediaController和MediaDisplay组件并给了另外一个实例名
_root[“flvContainer” + flagNum].addEventListener(“complete”, myListener);
};

4.新建一层,命名为action,在该层第一帧输入一下AS代码:

stop();
//数组myArray用来存储 载入的XML文档中的影片名称
var myArray = new Array();
//影片的总数
var flvTotal:Number;
var myXml = new XML();
myXml.ignoreWhite = true;
myXml.load(“list.xml”);
myXml.onLoad = function() {
var e = myXml.firstChild.childNodes;
flvTotal = e.length;
for (var i = 0; i myArray.push(e[i].attributes[“title”]);
}
init();
_root[“flvContainer”+flagNum].addEventListener(“complete”, myListener);
};
var myListener = new Object();
myListener.complete = function(eventObject) {
playNext();
};

用记事本写入下面内容作为播放列表,保存为list.xml:

<?xml version="1.0" encoding="utf-8" ?>
<flvLists>
<item title="1.flv" />
<item title="2.flv" />
<item title="3.flv" />
<item title="4.flv" />
</flvLists>

制作完成。OK

随机文章:

1、用CSS实现的一张图完成的导航条
https://www.onexin.net/photo-with-css-to-achieve-the-completion-of-the-navigation-bar/

2、PDO数据抽象简介及MySQL,PostgreSQL,ODBC,Oracle应用
https://www.onexin.net/pdo-data-abstraction-introduction-and-mysql-postgresql-odbc-oracle-applications/

3、Discuz!X站内开启视频播放代码
https://www.onexin.net/discuz-x-stations-open-video-player-code/

4、YouTube视频短网址插入Discuz!X播放
https://www.onexin.net/let-discuz-x-support-insert-youtube-video-short-url/

5、Ubuntu+Apache+PHP+MySQL+Memcached
https://www.onexin.net/ubuntuapachephpmysqlmemcached/

转载请注明出处:https://www.onexin.net/%e8%87%aa%e5%b7%b1%e5%88%b6%e4%bd%9cflv%e6%92%ad%e6%94%be%e5%99%a8/

Leave a Reply

Your email address will not be published. Required fields are marked *