Time for action – Playing embedded video

For our application design we are supposed to play an introduction movie when the application first starts. This video is normally some animated logo or similar and in our case it will be the Sojourner Mobile intro movie (sometimes referred to as an interstitial).

I'm going to assume that you aren't a video engineer and don't know a lot about MPEG-4, H.264, or B Frames, but you have some content that you want to get into your iOS project. This is one thing that gives a lot of new developers trouble and results in video not displaying on the device.

We can avoid all of this drama by simply using a tool that was designed for producing content for iOS devices. One such tool that you can use for this is iMovie. It has functionality for exporting iOS device compliant video that you can use with your projects.

  1. Import your content into iMovie and export it using the Share menu:
    Time for action – Playing embedded video
  2. When prompted for the video type that you want to export to, choose the Mobile size and press the Export button:
    Time for action – Playing embedded video

    Note that you can choose the Medium size as well, but since this is media that is being embedded into our game, and will count against our maximum application size, it is best to keep this content as small as possible so that you can keep it for other things such as game assets.

  3. Next we need to move the video into a special Unity assets folder called StreamingAssets. Unity will copy the files in this directory into our application bundle and put them in the appropriate location on the device so we can play them back at runtime:
    Time for action – Playing embedded video

    Now that we have our asset in the game we need to play it. The best way to do this is to have a single scene that does nothing other than display our movie and then loads the IntroCity scene.

  4. Let's create a new scene called GameIntro that will serve this purpose:
    Time for action – Playing embedded video
  5. Now that we have our GameIntro scene we can create an empty GameObject and attach a script to it that will play our movie and load the next level after it's over.
  6. Now, all we need is a simple script that we can attach to this GameObject and have start in the Start() of the script. We need to use the C# co-routine version of the Start() method as opposed to our normal version.
    using UnityEngine;
    using System.Collections;
    
    public class PlayIntroMovie : MonoBehaviour {
    
      // Use this for initialization
      IEnumerator Start () {
    
        iPhoneUtils.PlayMovie("Snowpocalypse2011.m4v", Color.black, iPhoneMovieControlMode.CancelOnTouch, iPhoneMovieScalingMode.AspectFill );
    	 
        yield return null;
          
        Application.LoadLevel("IntroCity");
    
      }
    
    }
    
  7. With this script attached to our empty GameObject we now have a complete intro movie system and when we start the game we will be greeted with the Interstitial of our company.

What just happened?

We have just finished our introduction scene by playing a movie to display our studio intro movie and then loading the level that we had been working on, which is the beginning town-level. Now our content is beginning to feel like the content that we would find on the App Store.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.74.44