文章搜索:
打开支付宝首页搜索“510617664”,即可领红包
  首页--> 计算机--> FLASH教程
 
写给想做flv播放器的朋友
http://www.xxqqss.com 学习轻松网 点击量:5037
 
写了个简单的flv播放器,给大家了解下flv播放器的基本功能~
测试的时候在同目录下创建个“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.rar

来源:闪吧论坛  作者:humorguy


打印】 【关闭
免责声明 :本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请发送fiyeadwyv@163.com
最热门点击排行
 
版权所有 2006-2021:学习轻松网 Copyright http://www.xxqqss.com All rights reserved 浙ICP备14013707号-1
广告联系电话: 13958357030 联系QQ:9792414 工具条下载