Unity3d 5.0 Dynamic play video, play music

Source: Internet
Author: User

1, unity3d 5.0 dynamic play Video

Tools: Mobile Movie texture.unitypackage2.1.1

Problem Description: Currently this third-party playback video tool does not provide music playback, and the online textbook is to drag the video directly. Cannot dynamically change the video that needs to be played

Workaround:

Core code: m_movietexture.path = "MOVIESAMPLES/HANDOFFATE.OGV";

Sample 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 dynamic play Music

Tools: Mobile Movie texture.unitypackage2.1.1

Problem Description: Regular drag audio to engineering, unrecognized; At present, this online textbook is to drag audio directly to. Cannot dynamically change the video that needs to be played

Workaround: Unable to recognize the audio, you need to create a resource folder in the project root directory; dynamic playback with program code control

Core code:

Sample Demo:

Public Audiosource Soundsource;


Soundsource = getcomponent<audiosource> ();

Soundsource.clip = (audioclip) resources.load ("Love", typeof (AudioClip));//Call the resources method to load the AudioClip resource
Soundsource.play ();

Unity3d 5.0 Dynamic play video, play music

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.