sk.baka.ambient.playerservice
Class PlayerService

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.app.Service
              extended by sk.baka.ambient.playerservice.PlayerService
All Implemented Interfaces:
ComponentCallbacks, MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener, IShoutcastListener

public final class PlayerService
extends Service
implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener, IShoutcastListener, MediaPlayer.OnBufferingUpdateListener

Simply plays required audio files. Invokes IPlayerListener handler when the playback is finished.

This service mainly prevents Android to kill the application when no activities are shown on screen.

Author:
Martin Vysny

Field Summary
(package private)  PlayerStateEnum playerState
          The playback state.
 
Fields inherited from class android.content.Context
ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MODE_APPEND, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NOTIFICATION_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, TELEPHONY_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Constructor Summary
PlayerService()
           
 
Method Summary
(package private)  IPlayerListener getInvocator()
          Returns a proxy which posts events using the SimpleBus object.
(package private)  void invokeError(String message, Throwable ex, boolean missing)
          An error occurred.
 void metadataReceived(String title, Map<String,String> metadata)
          Invoked when the radio transmits additional metadata.
 IBinder onBind(Intent intent)
           
 void onBufferingUpdate(MediaPlayer mp, int percent)
           
 void onCompletion(MediaPlayer arg0)
           
 void onCreate()
           
 void onDestroy()
           
 boolean onError(MediaPlayer player, int what, int extra)
           
 void onPrepared(MediaPlayer p)
           
 void opened(String name, String genre, boolean hasMetaint, Map<String,String> metadata)
          The stream was opened and the SHOUTcast metadata was read.
 
Methods inherited from class android.app.Service
dump, finalize, getApplication, onConfigurationChanged, onLowMemory, onRebind, onStart, onUnbind, setForeground, stopSelf, stopSelf, stopSelfResult
 
Methods inherited from class android.content.ContextWrapper
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getFilesDir, getFileStreamPath, getMainLooper, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, setTheme, setWallpaper, setWallpaper, startActivity, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

playerState

volatile PlayerStateEnum playerState
The playback state.

Constructor Detail

PlayerService

public PlayerService()
Method Detail

onCreate

public void onCreate()
Overrides:
onCreate in class Service

onDestroy

public void onDestroy()
Overrides:
onDestroy in class Service

onBind

public IBinder onBind(Intent intent)
Specified by:
onBind in class Service

getInvocator

IPlayerListener getInvocator()
Returns a proxy which posts events using the SimpleBus object.

Returns:
the proxy instance.

onCompletion

public void onCompletion(MediaPlayer arg0)
Specified by:
onCompletion in interface MediaPlayer.OnCompletionListener

invokeError

void invokeError(String message,
                 Throwable ex,
                 boolean missing)
An error occurred. The player is stopped and a stop event is generated.

Parameters:
message - the error message.
ex - the error cause, may be null if not known
missing - if true then this error was caused by a file missing.

onError

public boolean onError(MediaPlayer player,
                       int what,
                       int extra)
Specified by:
onError in interface MediaPlayer.OnErrorListener

onPrepared

public void onPrepared(MediaPlayer p)
Specified by:
onPrepared in interface MediaPlayer.OnPreparedListener

metadataReceived

public void metadataReceived(String title,
                             Map<String,String> metadata)
Description copied from interface: IShoutcastListener
Invoked when the radio transmits additional metadata.

Specified by:
metadataReceived in interface IShoutcastListener
Parameters:
title - the 'StreamTitle' metadata
metadata - all metadata

opened

public void opened(String name,
                   String genre,
                   boolean hasMetaint,
                   Map<String,String> metadata)
Description copied from interface: IShoutcastListener
The stream was opened and the SHOUTcast metadata was read.

Specified by:
opened in interface IShoutcastListener
Parameters:
name - the name of the radio station
genre - the genre
hasMetaint - if true then the radio stream will periodically transmit metadata (and the IShoutcastListener.metadataReceived(String, Map) will be invoked).
metadata - all present metadata.

onBufferingUpdate

public void onBufferingUpdate(MediaPlayer mp,
                              int percent)
Specified by:
onBufferingUpdate in interface MediaPlayer.OnBufferingUpdateListener


Copyright © 2007-2008. All Rights Reserved.