制作flv播放器。
来自:http://www2.flash8.net/teach/5786.htm
写了个简单的flv播放器,给大家了解下flv播放器的基本功能~
测试的时候在同目录下创建个“flv”文件夹,把要播放的视频文件放到里面,当然,相对应的playlist.xml也要修改一下。
测试的时候在同目录下创建个“flv”文件夹,把要播放的视频文件放到里面,当然,相对应的playlist.xml也要修改一下。
//==========视频初始化======================
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
my_video.attachVideo(ns);
ns.setBufferTime(5);
//=====从xml文件中获得待播放视频的各种信息====
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = loadData;
data_xml.load("playlist.xml");
var aPath = new Array();
temp = 0;
function loadData(success) {
if (success) {
//获得所有的文件名称
songTitel = new Array();
audioTracks = this.firstChild.childNodes;
song_total = audioTracks.length;
for (var i = 0; i<song_total; i++) {
aPath.push(audioTracks.attributes.path);
songTitel.push(audioTracks.attributes.title);
//=======创建播放列表按钮组========
filelistG_mc.attachMovie("filelist_mc","filelist_mc"+i,i);
filelistG_mc["filelist_mc"+i]._y = (i+1)*3 + 20*i;
filelistG_mc["filelist_mc"+i]._x = 4;
filelistG_mc["filelist_mc"+i].title_txt.text = songTitel;
filelistG_mc["filelist_mc"+i].onPress = function() {
listplay(this.getDepth());//=====给列表上的每个文件定义按钮事件
};
}
}
}
//==========构造函数========================
function listplay(path){
temp = path;
test.text = songTitel[path] + " playing..";
playvideo();
}
function playvideo (){
ns.stop();
currentVideo = aPath[temp];
ns.play(currentVideo);
}
//=============播放按钮控制==================
stop_btn.onPress = function(){
ns.seek(0);
ns.pause();
}
pause_btn.onPress = function(){
ns.pause();
}
play_btn.onPress = function(){
playvideo(path);
}
ns.onMetaData = function(obj) {
dur = obj.duration;
};
_root.onEnterFrame = videoUpdate;
lprog_mc.onPress = function(){
_root.onEnterFrame = scrubba;
}
lprog_mc.onRelease = lprog_mc.onReleaseOutside = function(){
ns.pause(false);
_root.onEnterFrame = videoUpdate;
}
function scrubba (){
var p = ((_root._xmouse - 11)/334.9);
if(_root._xmouse <= 345.9 && p >= 0){
ns.seek(p*dur);
ns.pause(true);
prog_mc._xscale = p*100;
}
}
function videoUpdate() {
var prog = ns.time/dur;
prog_mc._xscale = prog*100;
playlab_mc._x = 7.5 + prog*334.9;
var lprog = ns.bytesLoaded/ns.bytesTotal;
lprog_mc._xscale = lprog*100;
}
//=========声音控制=============
vidsound.attachAudio(ns);
var sou:Sound = new Sound(vidsound);
sou.setVolume(75);
SC_mc.onPress = function (){
this.onEnterFrame = setV;
}
SC_mc.onRelease = SC_mc.onReleaseOutside = function (){
delete this.onEnterFrame;
}
function setV (){
if(_root._ymouse >= 275 && _root._ymouse <= 336.5){
var soundP = (61.5 - (_root._ymouse - 275))/61.5;
sou.setVolume(soundP*100);
SC_mc._yscale = soundP*100;
myVolume = sou.getVolume();
}
}
mute_mc.onRelease = function() {
if (sou.getVolume() == 0) {
sou.setVolume(myVolume);
SC_mc._yscale = myVolume;
} else {
myVolume = sou.getVolume();
sou.setVolume(0);
SC_mc._yscale = 1;
}
}
附件: flv_player.rarvar nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
my_video.attachVideo(ns);
ns.setBufferTime(5);
//=====从xml文件中获得待播放视频的各种信息====
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = loadData;
data_xml.load("playlist.xml");
var aPath = new Array();
temp = 0;
function loadData(success) {
if (success) {
//获得所有的文件名称
songTitel = new Array();
audioTracks = this.firstChild.childNodes;
song_total = audioTracks.length;
for (var i = 0; i<song_total; i++) {
aPath.push(audioTracks.attributes.path);
songTitel.push(audioTracks.attributes.title);
//=======创建播放列表按钮组========
filelistG_mc.attachMovie("filelist_mc","filelist_mc"+i,i);
filelistG_mc["filelist_mc"+i]._y = (i+1)*3 + 20*i;
filelistG_mc["filelist_mc"+i]._x = 4;
filelistG_mc["filelist_mc"+i].title_txt.text = songTitel;
filelistG_mc["filelist_mc"+i].onPress = function() {
listplay(this.getDepth());//=====给列表上的每个文件定义按钮事件
};
}
}
}
//==========构造函数========================
function listplay(path){
temp = path;
test.text = songTitel[path] + " playing..";
playvideo();
}
function playvideo (){
ns.stop();
currentVideo = aPath[temp];
ns.play(currentVideo);
}
//=============播放按钮控制==================
stop_btn.onPress = function(){
ns.seek(0);
ns.pause();
}
pause_btn.onPress = function(){
ns.pause();
}
play_btn.onPress = function(){
playvideo(path);
}
ns.onMetaData = function(obj) {
dur = obj.duration;
};
_root.onEnterFrame = videoUpdate;
lprog_mc.onPress = function(){
_root.onEnterFrame = scrubba;
}
lprog_mc.onRelease = lprog_mc.onReleaseOutside = function(){
ns.pause(false);
_root.onEnterFrame = videoUpdate;
}
function scrubba (){
var p = ((_root._xmouse - 11)/334.9);
if(_root._xmouse <= 345.9 && p >= 0){
ns.seek(p*dur);
ns.pause(true);
prog_mc._xscale = p*100;
}
}
function videoUpdate() {
var prog = ns.time/dur;
prog_mc._xscale = prog*100;
playlab_mc._x = 7.5 + prog*334.9;
var lprog = ns.bytesLoaded/ns.bytesTotal;
lprog_mc._xscale = lprog*100;
}
//=========声音控制=============
vidsound.attachAudio(ns);
var sou:Sound = new Sound(vidsound);
sou.setVolume(75);
SC_mc.onPress = function (){
this.onEnterFrame = setV;
}
SC_mc.onRelease = SC_mc.onReleaseOutside = function (){
delete this.onEnterFrame;
}
function setV (){
if(_root._ymouse >= 275 && _root._ymouse <= 336.5){
var soundP = (61.5 - (_root._ymouse - 275))/61.5;
sou.setVolume(soundP*100);
SC_mc._yscale = soundP*100;
myVolume = sou.getVolume();
}
}
mute_mc.onRelease = function() {
if (sou.getVolume() == 0) {
sou.setVolume(myVolume);
SC_mc._yscale = myVolume;
} else {
myVolume = sou.getVolume();
sou.setVolume(0);
SC_mc._yscale = 1;
}
}