Unity3D 实现视频播放和声音同步(笔记)
2013-10-31 13:21
453 查看
这个代码有些杂乱 ,是工作中的一个文件,我特意拿出来保存在这里,希望自己和别人可以以后直接借鉴。
当然如果想要使用本文件 , 还要经过一些修改,因为这个文件单独拿出来是不能独立运行的,不过经过简单的修改就可以实现上述功能了,比如把按钮控制播放停止等等太加进来就基本可以使用。
仔细说下我的这个 代码的大概意思吧,首先 , 我这个文件是赋给一个plane对象的,在这个plane对象上面我想去播放视频,嗯,想法就是这么简单,然后主要功能就是完成 从 本地获得绝对路径 之后, 利用WWW类, 下载本地磁盘的视频,然后利用 renderer.material.mainTexture = www.movie;
把视频赋到plane的纹理里面, 这样Plane就可以播放视频了。但是我发现那个视频放出来没有声音,所以在网上面查了半天终于查到资料,
http://hi.baidu.com/ccoooolleerr/item/b19806a13506fcac29ce9dbb, 我参考这个人写的,模仿的把音频组件添加进来了,aud = gameObject.AddComponent<AudioSource>();
, 这句话,然后声音就都可以放出来了。
当然如果想要使用本文件 , 还要经过一些修改,因为这个文件单独拿出来是不能独立运行的,不过经过简单的修改就可以实现上述功能了,比如把按钮控制播放停止等等太加进来就基本可以使用。
仔细说下我的这个 代码的大概意思吧,首先 , 我这个文件是赋给一个plane对象的,在这个plane对象上面我想去播放视频,嗯,想法就是这么简单,然后主要功能就是完成 从 本地获得绝对路径 之后, 利用WWW类, 下载本地磁盘的视频,然后利用 renderer.material.mainTexture = www.movie;
把视频赋到plane的纹理里面, 这样Plane就可以播放视频了。但是我发现那个视频放出来没有声音,所以在网上面查了半天终于查到资料,
http://hi.baidu.com/ccoooolleerr/item/b19806a13506fcac29ce9dbb, 我参考这个人写的,模仿的把音频组件添加进来了,aud = gameObject.AddComponent<AudioSource>();
, 这句话,然后声音就都可以放出来了。
using UnityEngine; using System.Collections; public class pl_portmov : MonoBehaviour { // Use this for initialization void Start () { transform.parent = GameObject.Find("loving_movies").transform; transform.localPosition = new Vector3(0.6f, 0.009f, -0.7f); transform.localScale = new Vector3(0.84f, 0.001f, 0.8f); transform.localRotation = Quaternion.identity; transform.Rotate(0f, 0f, 0f, Space.World); //旋转角度 name = "movie_part"; aud = gameObject.AddComponent<AudioSource>(); //这里添加音频组件组件 } // Update is called once per frame void Update () { } /*接收 Button_queding传送的消息*/ private string filename; public WWW www; public static MovieTexture movtex; public AudioSource aud; public IEnumerator Getflnam(string flname) { filename = flname; //接收文件路径 yield return www = new WWW("file://" + flname); if (www.error != null) { Debug.Log("www error!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } if (www.isDone) Debug.Log("www.isDone"); movtex = www.movie as MovieTexture; renderer.material.mainTexture =movtex; movtex.loop = true; //同步播放音频 aud.audio.clip = movtex.audioClip; if (movtex.isReadyToPlay) { movtex.Play(); aud.audio.Play(); } } public void mov_play() { if (movtex.isReadyToPlay) { movtex.Play(); aud.audio.Play(); Debug.Log("movtex.Play() success"); } } public void mov_pause() { movtex.Pause(); aud.audio.Pause(); Debug.Log("movtex.Pause() success"); } public void mov_stop() { movtex.Stop(); aud.audio.Stop(); Debug.Log("movtex.Stop() success"); } }
相关文章推荐
- unity3d笔记(4)——声音,视频播放控制
- OpenCV笔记(二)实现获取视频并控制视频的播放速度
- Unity3D游戏开发之在Unity3D中实现视频播放
- 用VC2005实现视频文件与GPS轨迹同步播放
- Javacv使用ffmpeg实现音视频同步播放
- debian学习笔记7, mplayer smplayer详细配置说明.解决播放视频没有画面只有声音,w32codecs.w74codecs插件配置.
- 利用VideoView简单实现视频播放 包括 横竖屏切换 声音 亮度 暂停
- NDK开发——FFmpeg实现视频转YUV、视频转RGB显示、音频转PCM、音频播放、音视频同步
- Unity3D游戏开发之在Unity3D中视频播放功能的实现
- Android 学习笔记之SurfaceView的使用+如何实现视频播放...
- unity3d实现视频播放
- 关于Unity3D VideoPlayer播放视频中的声音的问题
- Html5视频播放器-VideoJS+Audio标签实现视频,音频及字幕同步播放
- Javacv使用ffmpeg实现音视频同步播放
- [置顶] 基于UDP实现的android局域网视频同步播放
- unity3d实现视频播放
- 频播放器,支持基本的拖动,声音、亮度调节,支持边播边缓存,支持视频本身自带 rotation 属性的旋转,重力旋转与手动旋转的同步支持,支持列表播放 ,直接添加控件为封,兼容一些 5.0 的过场效果
- Android 开关机动画的实现及支持MP4视频播放
- three.js插件实现立体动感视频播放效果
- Html5组件实现视频播放