Background:game consoles want to join the dance elements, the first idea is to develop dance games, and then through the animation to express the dance, to provide users with dance teaching experience, but the development of the dance game itself takes a long time (too few people), do not talk about the follow-up dance and music copyright, so now want to go another path , Play dance teaching videos in unity, add UI and some testing to achieve dance teaching, and after the framework is written, the content is easy to expand, after all, it doesn't need to be animated for every dance. But unity in video playback is a variety of egg pain, especially under Android, OK, the following is a lot of things from the online collation:
1 Win/mac First, you need Quick Time7.0 above on Windows and on your Mac. Unity supports video playback formats that are still pretty much like . mov,. mpg,. mpeg,. mp4,. avi,. asf, and even. H264 and so on, it is very simple to use, really Jane ~ ~ Single. under wiN/mac, Unity offers movietexture lines The imported video unity will be automatically converted. Movietextureinheriting with the texture class, provides a simple control play/pause/stop required for video playback:
pause |
pauses playing the movie. |
play |
starts playing the movie. |
Stop |
Stops playing the movie, and rewinds it to the beginning. |
movietextureGiven the parameters are not much, considering that the video will be downloaded from the network, detectionIsreadytoplay is necessary, IsPlaying gives whether the parameters in play, loop control whether loop playback, duration is a very useful thing, give the current play to the position.
AudioClip |
Returns the audioclip belonging to the movietexture. |
duration |
the time, in seconds, which the movie takes to play back completely. |
isplaying |
returns whether the movie is playing or not. |
isreadytoplay |
if the movie is downloading from a Web site, this returns If enough data have been downloaded so Playb ACK should is able to start without interruptions. |
Loop |
Set this to true to make the movie loop. |
OK, test, the specific way to use the rain pine gives a very detailed:
two ways to play the game video in Unity3d research. in the case of a planar display, the core code of the test code is as follows:
Renderer.material.mainTexture = movie; true; Movie. Play (); Movie. Pause (); Movie. Stop ();
But it is very uncomfortable to use, because can not meet the needs of the project, the teaching will definitely need video playback function, Fast forward, rewind, point playWait a minute. ForFast Forward, there are users through the same gameobject with the control script binding a audiosource pitch parameters can be controlled, but I do not have this effect in the test, may be wrong, the other solution is to seek third-party plug-ins AVPro QuickTime. This plugin can be used for fast forward, rewind, vertex playback, multi-window playback and so on (if under window, in the example is the video file and the internal parameters.), the suffix of the bin is removed.This plugin can only be used on Win/mac ~ ~,but this plugin code is a good example of studying unity's bottom.
2 Moving Endon the mobile side, Unity does not provide Movietexture,avpro QuickTime nor can it be used, its most basic display scheme using the Playfullscreenmovie () function for full-screen playback, according to its official website interpretation, mainly has the following aspects:
(1) The video stream is obtained directly from the device memory, so the file can only be provided separately, and the video file is placed in the streamingassets folder .
(2) In video playback, unity will stop, unity automatically resumes after playback, and the color in the screen will change to the background color of the player and resume after playback.
(3) in iOS, the inside is actually a method of calling MPMoviePlayerController
(4) formats to support: . mov,. mp4,. MPV, and. 3gp ,h.MPEG-4 Part 2 video
Handheld.playfullscreenmovie ("Starwars.mp4", Color.Black, Fullscreenmoviecontrolmode.canceloninput);
That means unity offers a simpler approach, a window approach, or a third-party plugin.
Mobile Movie Texture for Android
is a good, at least the actual test can be run under Android, but in the unity4.5 directly open there will be a problem, if you use unity4.1 first open and then use 4.5 no problem, it may be a resource problem.
The plugin uses an open source video codec library Theora, so he can only support the Ogg format of video and audio, in other words, the other format will be converted to the OGG format, video decoding in the run and then through the Unity GL Bottom Library in the corresponding area to draw. Relative to QuickTime
This plug-in provides a relatively simple function, but this aspect of the expansion, the more tangled is to provide the seek video fixed-point function is not very perfect, the position deviation is large, is not suitable for precise application.
2 Summary
For a day to tidy up, the overall said Unity provides video function is not ideal, if only play in the game and so on is still enough, but for the current demand is not enough, I hope unity can continue to improve in this area
Unity Video Playback