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:
.
main.m
VideoAppDelegate
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.sneeze.m4v
Go to the
Library of Congress,
get the file
0026A.mov
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
Save
To verify that the
0026A.mov
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
0026A.mov
is.
cd to the directory that holds 0026A.mov file 0026A.mov 0026A.mov: 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.
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
JaneVideo.zip
plays a You Tube video (with sound).
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)
Finish
MPMovieControlStyleNone
,
MPMovieControlStyleEmbedded
,
MPMovieControlStyleDefault
.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];
prepareToPlay
and
isPreparedToPlay
methods of the
MPMoviePlayerController
.
Note: a
MPMoviePlayerController
has all the methods of a
MPMediaPlayerPlayback
object.
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", controller.naturalSize.width, controller.naturalSize.height ); } }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?