Time for action – Streaming video

The first thing we need to do is make sure that an Internet connection is available. Once we know that the Internet is available we can start to stream our video. We need to check for a network connection because we want to respect the fact that our user may deactivate the network connection for Airplane Mode, trying to preserve battery life, or because our device may not be in an area of network connectivity.

We can determine whether or not the iOS device can reach the network by using the iPhoneSettings' internetReachability class variable. This will be updated as the network status changes and will also tell you what type of Internet connection you have available. For our purposes we simply need to check whether or not there is a connection of any kind. We can resolve this with a simple condition check:

if ( iPhoneSettings.internetReachability != iPhoneNetworkReachability.NotReachable )
{
}

It is very important that you perform this check for Internet connectivity. If your application tries to reach out to the Internet and fails and you do not deal with this gracefully, by either showing an error that is visible to the user or not performing the functionality that requires network access, Apple will reject the application. You should be prepared to test your game in Airplane Mode exclusively to know whether or not it is going to behave properly if there is no network connectivity.

Now we know that we can reach the Internet, we want to stream some video to the device. I have stored a video online that the iOS device can stream from our server:

if ( iPhoneSettings.internetReachability != iPhoneNetworkReachability.NotReachable )
{
iPhoneUtils.PlayMovieURL(http://www.sojournermobile.com/assets/unitybook/commercial.m4v, Color.black, iPhoneMovieControlMode.Hidden )
}

As you can see this isn't much different from playing back content that is stored on the device. As we want this to behave like a commercial we want to remove the player's ability to cancel this video or skip through it so we use the iPhoneMovieControlMode.Hidden enumeration to ensure that the player will have to watch the movie.

What just happened?

We have performed network detection to determine whether or not an Internet connection is available. After ensuring that a network connection was available we connected to a stream on the Internet and began playing our commercial.

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

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