Skip to content

Instantly share code, notes, and snippets.

@clamytoe
Last active August 29, 2015 14:27
Show Gist options
  • Save clamytoe/51343bfafc7eb2580acd to your computer and use it in GitHub Desktop.
Save clamytoe/51343bfafc7eb2580acd to your computer and use it in GitHub Desktop.
HKUSTx: COMP107x Introduction to Mobile Application Development using Android
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercise: Shooting Game with Background Music\n",
"---\n",
"## Objectives\n",
"\n",
"In this exercise you will learn about the use of the MediaPlayer class in Android, and how you can use it to play audio files. In addition, you will learn about the design of menu items and the use of the toolbar for menu items. At the end of this exercise you will be able to:\n",
"\n",
"* Use the MediaPlayer class to play audio files stored in the raw folder of your app's resources\n",
"* Control the playback of the audio using the methods provided by the MediaPlayer class\n",
"* Add menu items to the toolbar/actionbar of your app, and respond to user's interaction with the menu icons\n",
"\n",
"## Introduction\n",
"\n",
"This project demonstrates the use of the MediaPlayer class to add background music to the Shooting Game application. We will use the Activity's lifecycle methods and the MediaPlayer methods to start and stop the playing of the music. In addition, we will learn how to add menu buttons to the toolbar/action bar and how to respond to the user clicking on the menu buttons.\n",
"\n",
"## Textual Instructions\n",
"---\n",
"### Step 1: Examining the Project Files\n",
"\n",
"1. Download the [ShootingGameMusic.zip](http://w02.hkvu.hk/edX/COMP107x/w4/ShootingGameMusic.zip) file, unzip it and import the project into Android Studio.\n",
"2. Open the **menu_shooting_game.xml** file.\n",
"3. Open the **ShootingGame.java** file and activate the menu buttons in code.\n",
"\n",
"---\n",
"### Step 2: Updating the ShootingGame Activity\n",
"\n",
"1. In the **ShootingGame.java** file, note the // TODO items marked in the file. Replace the first comment in the onCreate() method with the code below.\n",
"\n",
" player = MediaPlayer.create(this, R.raw.braincandy);\n",
" player.setLooping(true);\n",
" play_music = true;\n",
"\n",
"2. In the onPause() method, replace the // TODO comment with the following code.\n",
"\n",
" if (play_music)\n",
" player.pause();\n",
"\n",
"3. In the onResume() method replace the // TODO comment with the following code.\n",
"\n",
" if (play_music)\n",
" player.start();\n",
"\n",
"4. Run the application to see the result."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment