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.

The application:didFinishLaunchingWithOptions: method of the application delegate gets the app’s bundle to find the full pathname of the video file. The full pathname is plugged into the URL object, which is plugged into the MPMoviePlayerController. (Despite is name, the MPMoviePlayerController is not a view controller.) The MPMoviePlayerController has a view in which it can show a movie. When the orange button is pressed, touchUpInside: makes the MPMoviePlayerController’s view visible by calling addSubview:.

Source code in

  1. main.m
  2. Class VideoAppDelegate
  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 a _itemFailedToPlayToEnd: message.

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).

Create the project

The MPMoviePlayerController in VideoAppDelegate.h requires the header file MediaPlayer.h. It also requires the MediaPlayer.framework. Select the name of the project at the top of the Xcode Project Navigator. Scroll the center pane down to Linked Framework and Libraries, press the plus button, and add the MediaPlayer.framework.

Drag sneeze.m4v into the Supporting Files folder in the Project Navigator.
Choose options for adding these files
Destination ☑ copy items into destiation group’s folder (if needed)

Other short videos

  1. 1984, the ad for the Apple Macintosh
  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: MPMovieControlStyleNone, MPMovieControlStyleEmbedded, MPMovieControlStyleDefault.

  2. Give the MPMoviePlayerController a green background color. Insert the following code into the application:didFinishLaunchingWithOptions: method of the application delegate immediately after we set the controller’s controlStyle.
    	//Give the controller a green background.
    	controller.backgroundView.backgroundColor = [UIColor greenColor];

  3. If the video doesn’t start playing immediately, call the prepareToPlay and isPreparedToPlay methods of the MPMoviePlayerController. Note: a MPMoviePlayerController has all the methods of a MPMediaPlayerPlayback object.

  4. 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 application delegate.
    - (void) isPreparedToPlayDidChange: (NSNotification *) notification {
    	NSAssert2(notification.object == controller,
    		@"%@ != %@", notification.object, controller);
    	if (controller.isPreparedToPlay) {
    		NSLog(@"controller.naturalSize == %g × %g",
    Add the following statement to the initWithFrame: method of the View immediately above the existing call to addObserver:selector:name:object:.
    	[center addObserver: self
    		selector: @selector(isPreparedToPlayDidChange:)
    		name: MPMediaPlaybackIsPreparedToPlayDidChangeNotification
    		object: controller
    Can you change the size of the MPMoviePlayerController to the natural size?

  5. Why is the status bar echoed above the movie?