Unity3d playing video using the Easymovietexture plugin

Source: Internet
Author: User

Unity3d for video playback compatibility personally feel very bad, previously wrote a use Unity3d own some of the features to play video, the link is as follows:

Http://www.cnblogs.com/xiaoyulong/p/8627016.html

Today we use the Easymovietexture plugin to play video playback videos. Personally feel that easymovietexture plug-in is still relatively easy to use, the inside encapsulated a lot of APIs, using it very convenient. There is a bad place is a lot of methods only in the video playback has the effect, that is to feel a bit of a pit.

For example, create a new object, hang up the Mediaplayerctrl script will basically be able to complete the video playback. A detailed introduction to the Mediaplayerctrl script can be seen in this link https://wenku.baidu.com/view/4cea74a918e8b8f67c1cfad6195f312b3169ebfe.html, I say here a few simple

strFileName: Enter the traditional file name in the Streamingassets folder. We can also enter the path.

Target Material: Connect gameobject to update the video map. It's just that you want to show the screen on which object, you drag it in.

B Loop: Whether to loop playback.

B Auto Play: Automatically play when activated.

Here are some of the common methods I encapsulated, should be able to meet a simple video player development, very simple, the code is as follows:

1 usingSystem.Collections;2 usingSystem.Collections.Generic;3 usingUnityengine;4 5  Public classVideocontroller:monobehaviour6 {7     PrivateMediaplayerctrl _mediaplayer;8     Private BOOL_isplaying;//whether the video is playing9     Private float_totaltime;//Total video LengthTen     Private float_currenttime;//video Current playback duration One  A     Private voidStart () -     { - Init (); the     } -  -     Private voidInit () -     { +_mediaplayer = This. Getcomponent<mediaplayerctrl>(); -     } +  A     /// <summary> at     ///whether the video is playing -     /// </summary> -      Public BOOLisplaying -     { -         Get -         { in             if(_mediaplayer.getcurrentstate () = =mediaplayerctrl.mediaplayer_state. PLAYING) -             { to_isplaying =true; +             } -             Else the             { *_isplaying =false; $             }Panax Notoginseng             return_isplaying; -         } the     } +     /// <summary> A     ///Total video Length the     /// </summary> +      Public floatTotalTime -     { $         Get $         { -             if(isplaying) -             { the                 return_mediaplayer.getduration ()/ +; -             }Wuyi             return-1; the         } -     } Wu     /// <summary> -     ///video Current playback duration About     /// </summary> $      Public floatcurrenttime -     { -         Get -         { A             if(isplaying) +             { the                 return_mediaplayer.getseekposition ()/ +; -             } $             return-1; the         } the     } the     /// <summary> the     ///whether the video is looped back -     /// </summary> in      Public BOOLIsloop the     { the         Get About         { the             return_mediaplayer.m_bloop; the         } the         Set +         { -_mediaplayer.m_bloop =value; the         }Bayi     } the  the     /// <summary> -     ///Read Video -     /// </summary> the     /// <param name= "_path" >Video Path</param> the      Public voidLoadmovie (string_path) the     { the _mediaplayer.load (_path); -     } the     /// <summary> the     ///Video Playback the     /// </summary>94      Public voidMovieplay () the     { the _mediaplayer.play (); the     }98     /// <summary> About     ///Video Pause -     /// </summary>101      Public voidMoviepause ()102     {103 _mediaplayer.pause ();104     } the     /// <summary>106     ///The video stops playing. 107     ///the difference between stop and pause is that when you stop, the video plays from the beginning, and the pause is where it pauses. 108     /// </summary>109      Public voidmoviestop () the     {111 _mediaplayer.stop (); the     }113     /// <summary> the     ///Video Replay the     /// </summary> the      Public voidMoviereplay ()117     {118 _mediaplayer.stop ();119 _mediaplayer.play (); -     }121     /// <summary>122     ///set the video playback speed. 123     ///This method can be used to do fast forward function, but cannot do fast rewind function124     /// </summary> the     /// <param name= "_i" ></param>126      Public voidSetmoviespeed (int_i)127     { - _mediaplayer.setspeed (_i);129     } the     /// <summary>131     ///video jumps to the specified time playback the     /// </summary>133     /// <param name= "Time" ></param>134      Public voidMovietotime (floatTime )135     {136_mediaplayer.seekto ((int) (Time * +));137     }138}

About the video playback progress bar display, has been to pull the progress bar to adjust the video playback progress, these functions we do some simple calculation can be achieved, very simple, here is not on the code.

Unity3d playing video using the Easymovietexture plugin

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.