Video: Fred Ott’s Sneeze

Filmed by Thomas Edison in 1894, this 48-frame blockbuster was the first movie to be copyrighted. Don’t miss the two sequels, Fred Ott Holding a Bird and Electrocuting an Elephant.

As in Gone, the view controller uses the bundle object to create a URL leading to the media file. The URL is then plugged into a MPMoviePlayerController. (Despite is name, the MPMoviePlayerController is not a view controller. But a MPMoviePlayerController does have all the methods of protocol MPMediaPlayerPlayback object.) The MPMoviePlayerController has a view in which it can show a video. When our button is pressed, touchUpInside: adds the MPMoviePlayerController’s view to the big white View, covering it up entirely. When the playback is finished, the MPMoviePlayerController’s view is removed from the big white View.

Source code in

  1. Class AppDelegate: unchanged.
  2. Class ViewController. The view controller creates the MPMoviePlayerController, starts it playing, and eventually receives the MPMoviePlayerPlaybackDidFinishNotification from it.
  3. Class View. This big white view is removed from the window when the movie starts to play, and is put back into the window when the movie is finished.
  4. sneeze.m4v

Get the video file

Go to the Library of Congress, get the file where it says “Quick Time format”, download it to your Mac. I chose .mov format because it was on the list of supported formats. But to get the file to play in an iPhone app, I had to convert it from .mov to .m4v. Control-click on the file, Open With QuickTime Player,
File → Save As…
Save As: sneeze.m4v
Format: iPhone

To verify that the file was downloaded safely, and successfully converted to m4v, type command-i (the Get Info command) on sneeze.m4v and see if the Preview section (under Open with) will play the video.

Also open a Terminal window and use the file program to determine what type of file is.

cd to the directory that holds
file Apple QuickTime movie (fast start)

file sneeze.m4v
sneeze.m4v: ISO Media, MPEG v4 system, iTunes AVC-LC

If the video file is damaged, the MPMoviePlayerController will print an _itemFailedToPlayToEnd: message.

Create the project

Put sneeze.m4v on your Macintsh Desktop and make sure you can play it. Then drag the file into the Supporting Files folder in the Xcode Project Navigator.
Choose options for adding these files:
Destination ☑ Copy items if needed
Add to targets: ☑ Video

Select the Video project at the top of the Project Navigator. At the top of the center panel of Xcode, select Build Phases. Make sure sneeze.m4v is listed under Copy Bundle Resources.

You Tube Videos

I converted a You Tube video to .mp4 format with ixconverter. Paste in the URL of the video in front of the yellow CONVERT button and press the button. The app plays a You Tube video (with sound).

Other short videos

  1. 1984, the ad for the Apple Macintosh. You Tube.
  2. Daisy Girl. Crude by today’s standards, in 1964 it was the the most frightening TV commercial ever made.
  3. Ranger 7 impacts at 6,000 miles per hour, July 31, 1964. LIVE FROM THE MOON!
  4. The Alka-Selter prison commercial.

Things to try

  1. Try the other types of control style:
    1. MPMovieControlStyle.None
    2. MPMovieControlStyle.Embedded
    3. MPMovieControlStyle.Default (?)

  2. There may be black margins on either side of the movie, depending on its the size and shape and the MPMovieScalingMode you specified for it. Give the MPMoviePlayerController a green background color. Insert the following code into the init method of the view controller immediately after we set the MPMoviePlayerController’s controlStyle.
    		//Give the moviePlayerController a green background.
    		moviePlayerController.backgroundView!.backgroundColor = UIColor.greenColor();

  3. Give the movie a subtitle. Insert the following code into the init method of the view controller after the call to prepareToPlay.
    		let label: UILabel = UILabel(frame: CGRectZero);
    		label.text = " My hovercraft is full of eels. ";
    		let font: UIFont = UIFont.systemFontOfSize(UIFont.labelFontSize());
    		label.frame.size = label.text!.sizeWithAttributes([NSFontAttributeName: font]);
    		let b: CGRect = moviePlayerController.view.bounds;
    		//Center the label along the bottom edge of the moviePlayerController's view. = CGPointMake(
    			b.origin.x + b.size.width / 2,
    			b.origin.y + b.size.height - 3.2 * label.frame.size.height);
    		//Keep the label along the bottom edge of the moviePlayerController's view.
    		label.autoresizingMask =
    			| UIViewAutoresizing.FlexibleRightMargin
    			| UIViewAutoresizing.FlexibleTopMargin;
    		label.backgroundColor = UIColor.clearColor();
    		label.textColor = UIColor.yellowColor();
    		label.textAlignment = NSTextAlignment.Center;

  4. The method playbackDidFinish is usually called because we have reached the end of the video file. In this case, we get no output from the prints. But what is the output if you press the Done button in the upper left corner of the movie’s controls? Note that 2 is the value of MPMovieFinishReason.UserExited.

  5. We can print the dimensions in pixels of the movie, but only when the MPMoviePlayerController is prepared to play the movie. Add the following method to the view controller.
    	func isPreparedToPlayDidChange(notification: NSNotification) {
    		assert(notification.object as MPMoviePlayerController == moviePlayerController,
    			"isPreparedToPlayDidChange: \(notification.object) != \(moviePlayerController)");
    		if moviePlayerController.isPreparedToPlay {
    			print("moviePlayerController.naturalSize = \(moviePlayerController.naturalSize)");
    Add the following statement to the init method of the view controller immediately above the existing call to addObserver(_:selector:name:object:).
    			selector: "isPreparedToPlayDidChange:",
    			name: MPMediaPlaybackIsPreparedToPlayDidChangeNotification,
    			object: moviePlayerController);
    moviePlayerController.naturalSize = (320.0,240.0)
    Can you change the size of the MPMoviePlayerController to its natural size?