Unity3d 调用外部视频

movieTexture.js

[javascript] view plain copy print ?
  1. public var url="file:///c:/sample.ogg";    
  2.     
  3. function Start ()    
  4. {    
  5. url="file:///" + Application.dataPath + "/video/sample.ogg";    
  6. print(url);    
  7. // Start download     
  8. var www = new WWW(url);    
  9. // Make sure the movie is ready to start before we start playing     
  10. var movieTexture = www.movie;    
  11. print("downloading...");    
  12. while (!movieTexture.isReadyToPlay)    
  13. {    
  14.     print(www.progress);    
  15.     yield;    
  16. }    
  17. print("download complete");    
  18. print(www.url);    
  19.     
  20. // Initialize gui texture to be 1:1 resolution centered on screen     
  21. guiTexture.texture = movieTexture;    
  22.     
  23. transform.localScale = Vector3 (0,0,0);    
  24. transform.position = Vector3 (0.5,0.5,0);    
  25. guiTexture.pixelInset.xMin = -movieTexture.width / 2;    
  26. guiTexture.pixelInset.xMax = movieTexture.width / 2;    
  27. guiTexture.pixelInset.yMin = -movieTexture.height / 2;    
  28. guiTexture.pixelInset.yMax = movieTexture.height / 2;    
  29.     
  30. // Assign clip to audio source     
  31. // Sync playback with audio     
  32. audio.clip = movieTexture.audioClip;    
  33.     
  34. // Play both movie & sound     
  35. movieTexture.Play();    
  36. audio.Play();    
  37. }    
  38. // Make sure we have gui texture and audio source     
  39. @script RequireComponent (GUITexture)    
  40. @script RequireComponent (AudioSource)    
 

 

ogg媒体文件放在:

工程: assets/video

exe: data/video

可以本地访问

参考:

http://unity3d.com/support/documentation/ScriptReference/WWW-movie.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值