Press a tab to play a selection from each movement of Beethoven’s Pastoral Symphony. For a cartoon treatment, see the 1940 Disney Fantasia.
This app has a row of five
ViewController
s
under a
tab bar controller.
The
tabBarController:didSelectViewController:
method of the tab bar controller’s
delegate
is called when the user presses a tab.
This method plays the sound file
of the view controller belonging to that tab.
If you press the same tab again while the sound is playing,
it will immediately restart the file from the beginning.
We want to play the sound file when the user presses the
ViewController
’s
tab,
not when the
ViewController
’s
view becomes visible.
If we were to play the file when the view became visible,
the first movement would starting playing automatically
as soon as the app was launched,
before any tab was pressed.
That’s why we do not play the sound file in the
viewDidAppear:
method of the
ViewController
.
We can,
however, stop the sound file in the
viewWillDisappear:
method of the
ViewController
.
main.m
PastoralAppDelegate
.
The application delegate is also the delegate of the tab bar controller.
ViewController
.
There are five of them.
I didn’t bother with tab bar images.I.mp3
(Allegro ma non troppo)II.mp3
(Andante molto mosso)III.mp3
(Allegro)IV.mp3
(Allegro)V.mp3
(Allegretto)
Drag the five
.mp3
files into the Supporting Files folder of the project.
Choose options for adding these files.
Destination ☑ Copy items into destination group’s folder
(if required).