1 playing video with Ngui

Source: Internet
Author: User

Use Movietexture, but there are only play,stop,pause 3 ways

Unity3d original support video playback, not uitexture but with Movietexture.
Movietexture.playe (); Play
Movietexture.pause (); pause
Movietexture.stop (); stop

Movietexture.loop = True means loop playback, false means not looping

Use render Texture If you want to render 3d in unity to your Texture, or if you are playing a video file directly

Just use the movie texture (PC-side support only) mobile iOS, Android words using mobile Movie texture plugin can be;

And there's tween animation.

http://blog.csdn.net/g__dragon/article/details/17371935

This is the following connection, after testing is correct, but can not use QuickTime, as long as the OGG,OGV format of the video can be.

Using Ngui to play a video, first you have to import your video

You must have QuickTime software installed on your PC, no, go next, if it is a Windows system, reboot after installation.

Next, convert your video format, and if your video doesn't play in QuickTime, you won't be able to play it in unity and turn your video into. MOV format (if your video cannot be played in QuickTime).

Of course, if you don't want to wait for unity to convert when you import the video, you can convert the video to OGV or Ogg format in advance, since unity is supported by default in both formats, and can be played directly when imported without conversion.

Although the web says QuickTime supports a lot of video types, but actually found that the same format can be played, and some will not play. So before you import unity, put it in QuickTime and try it.

After the break-in will be such a video file, a sound file (if your video has a sound).

Next two see a Ngui texture control, drag the video into the texture property, and then drag the 1.audio to the texture control.

Add three buttons and a slider to control playback, pause, stop, and playback progress respectively. The Buttonmessage script is added on each button and the target is texture,funtionname to Movieplanebuttons, which is used to pass the playback state information to the texture.

The next step is to play the code.

The movie texture must be attached to the game object to play (specify the audio to play in the drawing view)
Public Movietexture _moivetexture;
float Ftimenow = 1;//Current playback time
Public UISlider _uislider;//The progress bar used to display the playback progress
string strplaystate = "null";//Playback status

void Start ()
{

_moivetexture.loop = true;
Hidemovieplane ();
}


void Update ()
{
TimeControl ();
}

Controlling film and film sounds
void Movieplanebuttons (Gameobject obj)
{
if (Obj.name = = "Btn-play")
{
if (!_moivetexture.isplaying)
{
Play a movie
_moivetexture.play ();
Play a sound on an object (sub-object of the movie)
Transform.audio.Play ();
Strplaystate = "Play";
}
}

if (Obj.name = = "Btn-pause")
{
if (_moivetexture.isplaying)
{
Pause and play is the continuation
_moivetexture.pause ();
Transform.audio.Pause ();
Strplaystate = "Pause";
}
}
if (Obj.name = = "Btn-stop")
{
if (_moivetexture.isplaying)
{
The end of the play is a start again
_moivetexture.stop ();
Transform.audio.Stop ();
Strplaystate = "Stop";
}
}
}

   //<summary>
   //show current playback time
   //</summary
    void TimeControl ()
    {
         if (strplaystate = = "Play")
        {
             Ftimenow = ftimenow + 1 * time.deltatime;
       }
        Else if (strplaystate = = "Pause")
         {}
        else if (strplaystate = = "Stop")
         {
            ftimenow = 0f;
       }
        _uislider.value = ( Ftimenow/_moivetexture.duration);

}

1 playing video with Ngui

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.