1、Unity3d 5.0 动态播放视频
工具:Mobile Movie Texture.unitypackage2.1.1
问题描述:目前这个第三方播放视频工具不提供播放时音乐,并且网上教材都是将视频直接拖曳。无法动态更改需要播放的视频
解决方法:
核心代码: m_movieTexture.Path = "MovieSamples/HandOfFate.ogv";
试例Demo:
[RequireComponent(typeof(MMT.MobileMovieTexture))]
public class TestMobileTexture : MonoBehaviour
{
private MMT.MobileMovieTexture m_movieTexture;
void Awake()
{
m_movieTexture = GetComponent<MMT.MobileMovieTexture>();
//
m_movieTexture.onFinished += OnFinished;
}
void OnFinished(MMT.MobileMovieTexture sender)
{
Debug.Log(sender.Path + " has finished ");
}
private void OnGUI()
{
GUILayout.BeginArea(new Rect(0.0f, 0.0f, Screen.width, Screen.height));
var currentPosition = (float)m_movieTexture.PlayPosition;
var newPosition = GUILayout.HorizontalSlider(currentPosition,0.0f,(float)m_movieTexture.Duration);
if (newPosition != currentPosition)
{
m_movieTexture.PlayPosition = newPosition;
}
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
if (GUILayout.Button(m_movieTexture.IsPlaying ? "Pause" : "Play"))
{
if(m_movieTexture.IsPlaying)
{
m_movieTexture.Pause = true;
}
else
{
if(!m_movieTexture.Pause)
{
m_movieTexture.Path = "MovieSamples/HandOfFate.ogv";
m_movieTexture.Play();
}
else
{
m_movieTexture.Pause = false;
}
}
}
if (GUILayout.Button("Stop"))
{
m_movieTexture.Stop();
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
}
2、Unity3d 5.0 动态播放音乐
工具:Mobile Movie Texture.unitypackage2.1.1
问题描述:常规拖曳音频到工程,无法识别;目前这个网上教材都是将音频直接拖曳到。无法动态更改需要播放的视频
解决方法:无法识别音频,需要在工程根目录在创建一个Resource文件夹;动态播放用程序代码控制
核心代码:
试例Demo:
public AudioSource SoundSource;
SoundSource = GetComponent<AudioSource>();
SoundSource.clip = (AudioClip)Resources.Load("love", typeof(AudioClip));//调用Resources方法加载AudioClip资源
SoundSource.Play();