flash通过xml加载视频要怎么做啊~~~~~

flash通过xml加载视频要怎么做啊~~~~~,第1张

1. xml文件,<root>

<video>

<url>xxx<url>

</video>

</root>

2.Flash中加载xml。

package {

import flash.display.MovieClip

import flash.net.URLLoader

import flash.events.Event

import flash.net.URLRequest

public class Weather extends MovieClip {

private var xmlloader:URLLoader

private var xml:XML

private var videourl:String

private var rand:Number = Math.random()

private var urlweather:String = "http://flash.weather.com.cn/xml/upload.xml?rand="+rand"

//private var urlweather:String = "upload.xml"

public function Weather() {

xmlloader = new URLLoader()

xmlloader.load(new URLRequest(urlweather))

xmlloader.addEventListener(Event.COMPLETE,onCompleteXml)

}

private function onCompleteXml(e:Event):void

{

xml = XML(e.target.data)

/ /trace(xml)

var xmllist:XMLList = xml.elements()

var lengths:int = xmllist.length()

videourl = xmllist[0].url; //

}

}

// 视屏代码、

videoSprite = new Sprite()

movieObj = new Object()

netConnection = new NetConnection()

netConnection.connect(null)

netStream = new NetStream(netConnection)

customClient= {onMetaData:metaDataHandler}

netStream.client = customClient

netStream.play(videourl) //此videourl变量xml中的视屏路径地址。

netStream.addEventListener(NetStatusEvent.NET_STATUS, statusHandler)

video = new Video(598,336)

video.attachNetStream(netStream)

videoSprite.addChild(video)

this.addChild(videoSprite)

}

关于视屏的各种控制我就不写了。

加载XML

var loader:URLLoader = new URLLoader()

loader.load(new URLquest("xml文件")) 比如(data.xml)

loader.addEventListener(Event.COMPLETE,onComplete)

解析XML

function onComplete(e:Event):void

{

var xml:XML = e.target.data

var xmllist:XMLList=xml.elements()

var len:uint=xmllist.length()

}

视屏

var myCon:NetConnection=new NetConnection()

//(2)-----建 立播放视频 的本地连接

myCon.connect(null)

///(3)声明一个视频流

var myStr:NetStream = new NetStream(myCon)

//(4)----声明一个视频显示容器

video1=new Video()

addChildAt(video,0)//把video添加到显示 列表的第1层

//video.width = 500

//video.height = 350

video.attachNetStream(myStr)

///(5)获取视频 长度 对象

var cd:Number = 0

var dx:Object=new Object()

dx.onMetaData = onMetaData//对名胜dx的元数据事件,调用onMetaData方法

function onMetaData(data:Object)

{

cd = data.duration//cd获取数据的持续时间

}

myStr.client = dx//为myStr调用回调方法,获妈对象dx

myStr.play(xmllist[0].后面xml里面写的就是啥)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/8018755.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存