1 / 11

Basic Audio and Video

Basic Audio and Video. Audio. Audio. Primary components Audio file stored in ‘raw’ folder within ‘res’ folder ‘raw’ directory must be created while many formats supported, .mp3 is most stable across devices Instance of MediaPlayer android.media.MediaPlayer key methods create

nyx
Télécharger la présentation

Basic Audio and Video

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Audio and Video

  2. Audio

  3. Audio • Primary components • Audio file • stored in ‘raw’ folder within ‘res’ folder • ‘raw’ directory must be created • while many formats supported, .mp3 is most stable across devices • Instance of MediaPlayer • android.media.MediaPlayer • key methods • create • static convenience method for instantiation and preparation • start

  4. Sample code - MediaPlayer MediaPlayeraudioPlayer; audioPlayer = MediaPlayer.create(this, R.raw.audio_file_name); //no extension on file name audioPlayer.setAudioStream(AudioManager.STREAM_MUSIC); audioPlayer.start();

  5. MediaPlayer – coding issues • Other information • audioPlayer.stop(), pause(), and resume() • audio does not automatically stop if activity pauses • only if application stops • audioPlayer.release() should be called when done • MediaPlayers can be expensive • frees resources • Can use a BroadcastReceiver to allow hardware control (e.g. play, pause, skip, etc. on headset) • Can use Service to continue playback when App stops

  6. MediaPlayer – coding issues • One of the prepare() methods must be called • prepare() method • called automatically by create() method • OK if using a file • prepareAsync () method • cannot use create() convenience method • starts MediaPlayer in a new thread • better for streaming audio • app does not ‘hang’ if waiting for buffered data

  7. Video

  8. Video • Primary components • Video file • .3gp file • new standard supported by 3G phones • can be stored in res/raw folder • don’t supply extension in call • can be stored within device’s file system (i.e. SD card) • VideoView widget • typical widget in xml layout file • key methods • setVideoPath (full path and file name with extension) • start

  9. Sample code - VideoView //Video stored on SD Card VideoView vv = (VideoView)findViewById(R.id.vvVideo); vv.setVideoPath("/sdcard/filename.3gp"); vv.start(); or: //Video stored in raw directory VideoViewvv = (VideoView)findViewById(R.id.vvVideo); vv.setVideoPath("android.resource://edu.csci153/raw/filename"); vv.start();

  10. Internal file system Emulator or attached device

  11. Internal file system • Display files within eclipse • Window…Show View…Other…File Explorer • avoid ‘data’ directory • emulator allows access • system directory – restricted access on an actual device • Copy files to/from device within eclipse • icons in File Explorer • copy to: ‘Push a file onto the device’ icon • copy from: ‘Pull a file from the device’ icon • delete from device: ‘Delete the selection’ icon

More Related