1 of 24

Prof. Christopher Rasmussen

May 13, 2015

CISC 181

Android:

Multimedia

2 of 24

News

  • No lecture Friday
    • Extra office hours for project questions: Friday, 9 am -- 1 pm

3 of 24

News

  • No lecture Friday
    • Extra office hours for project questions: Friday, 9 am -- 1 pm
  • Regular office hours
    • Instructor: Today, 1-3 pm
    • TA: Thursday, 3:30-5:30 pm

4 of 24

News

  • No lecture Friday
    • Extra office hours for project questions: Friday, 9 am -- 1 pm
  • Regular office hours
    • Instructor: Today, 1-3 pm
    • TA: Thursday, 3:30-5:30 pm
  • Final review on Monday is last lecture

5 of 24

News

  • No lecture Friday
    • Extra office hours for project questions: Friday, 9 am -- 1 pm
  • Regular office hours
    • Instructor: Today, 1-3 pm
    • TA: Thursday, 3:30-5:30 pm
  • Final review on Monday is last lecture
  • Sign-up page for project demos will be up this afternoon--I will send class e-mail
    • Monday: 10, 10:30 am start times
    • Tuesday: 10 am-6:30 pm start times
    • Wednesday: 10 am-3:30 pm start times

6 of 24

Sounds

  • SoundPool class for playing short sound effects like shot/crash/power-up

7 of 24

Sounds

  • SoundPool class for playing short sound effects like shot/crash/power-up
    • Construct object, load() each sound during initialization phase and associate with ID
      • .mp3, .ogg, .wav in res/raw

8 of 24

Sounds

  • SoundPool class for playing short sound effects like shot/crash/power-up
    • Construct object, load() each sound during initialization phase and associate with ID
      • .mp3, .ogg, .wav in res/raw
    • play() method plays a sound with an ID immediately, with different options on volume, pitch, and repetition

9 of 24

Sounds

  • SoundPool class for playing short sound effects like shot/crash/power-up
    • Construct object, load() each sound during initialization phase and associate with ID
      • .mp3, .ogg, .wav in res/raw
    • play() method plays a sound with an ID immediately, with different options on volume, pitch, and repetition
  • MediaPlayer is a good option for things like background music

10 of 24

MediaPlayer MP =

MediaPlayer.create(getApplicationContext(),

R.raw.music); // music.mp3, etc.

try { MP.prepare(); } catch (Exception e) { }

11 of 24

MediaPlayer

MediaPlayer MP =

MediaPlayer.create(getApplicationContext(),

R.raw.music); // music.mp3, etc.

try { MP.prepare(); } catch (Exception e) { }

MP.setVolume(.5f, .5f);�MP.setLooping(true);

MP.start();�

12 of 24

MediaPlayer

MediaPlayer MP =

MediaPlayer.create(getApplicationContext(),

R.raw.music); // music.mp3, etc.

try { MP.prepare(); } catch (Exception e) { }

MP.setVolume(.5f, .5f);�MP.setLooping(true);

MP.start();�…

MP.pause(); // stop() requires prepare() to start() again

13 of 24

Text To Speech

TextToSpeech mTTS;

mTTS = new TextToSpeech(

getApplicationContext(),

new TextToSpeech.OnInitListener() {� public void onInit(int status) { }� });

14 of 24

Text To Speech

TextToSpeech mTTS;

mTTS = new TextToSpeech(

getApplicationContext(),

new TextToSpeech.OnInitListener() {� public void onInit(int status) { }� });

mTTS.speak(

myTextString,

TextToSpeech.QUEUE_FLUSH, // vs. QUEUE_ADD

null);

15 of 24

Text To Speech: Extras

  • You can get the text from an EditText view ET with ET.getText().toString()

16 of 24

Text To Speech: Extras

  • You can get the text from an EditText view ET with ET.getText().toString()
  • Create text "shortcuts" to play sounds with

mTTS.addSpeech(String,

package name,

sound resource ID)

17 of 24

Text To Speech: Extras

  • You can get the text from an EditText view ET with ET.getText().toString()
  • Create text "shortcuts" to play sounds with

mTTS.addSpeech(String,

package name,

sound resource ID)

  • Modify speech characteristics with
    • setPitch(float) // 1.0f is normal
    • setSpeechRate(float) // 1.0f is normal

18 of 24

  • Class for reading sensors:
    • Light level
    • Temperature (ambient)
    • Accelerometer (gravity)
    • Magnetic (i.e., compass) direction
    • Atmospheric pressure
    • Heart rate
    • Etc.

19 of 24

  • Class for reading sensors:
    • Light level
    • Temperature (ambient)
    • Accelerometer (gravity)
    • Magnetic (i.e., compass) direction
    • Atmospheric pressure
    • Heart rate
    • Etc.
  • Not all may be supported on device, so

List<Sensor> getSensorList(Sensor.TYPE_ALL)

20 of 24

  • Class for reading sensors:
    • Light level
    • Temperature (ambient)
    • Accelerometer (gravity)
    • Magnetic (i.e., compass) direction
    • Atmospheric pressure
    • Heart rate
    • Etc.
  • Not all may be supported on device, so

List<Sensor> getSensorList(Sensor.TYPE_ALL)

  • Also has constants like
    • GRAVITY_EARTH, GRAVITY_JUPITER, etc.
    • LIGHT_SUNLIGHT, LIGHT_SHADE

21 of 24

Sensors: Accelerometer

SensorManager SM = (SensorManager)

getApplicationContext().getSystemService(Context.SENSOR_SERVICE);�SM.registerListener(

new SensorListener(), // this is our custom class

SM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),

SM.SENSOR_DELAY_NORMAL);

22 of 24

Sensors: Accelerometer

SensorManager SM = (SensorManager)

getApplicationContext().getSystemService(Context.SENSOR_SERVICE);�SM.registerListener(

new SensorListener(), // this is our custom class

SM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),

SM.SENSOR_DELAY_NORMAL);

class SensorListener implements SensorEventListener {� public void onSensorChanged(SensorEvent event) {� if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {� aX = event.values[0]; aY = event.values[1];� aZ = event.values[2]; haveAccel = true;� }� }

public void onAccuracyChanged(Sensor sensor, int accuracy) { }

}

23 of 24

And if you're really bored...

24 of 24

And if you're really bored...

VIBRATION!!!