com.virtual.tour.road.com.virtual.tour.road.vista

## Class MusicService

- java.lang.Object
- - android.content.Context
  - - android.content.ContextWrapper
    - - android.app.Service
      - - com.virtual.tour.road.com.virtual.tour.road.vista.MusicService

- All Implemented Interfaces:
    android.content.ComponentCallbacks, android.content.ComponentCallbacks2, android.media.MediaPlayer.OnCompletionListener, android.media.MediaPlayer.OnErrorListener, android.media.MediaPlayer.OnPreparedListener

      public class MusicService
      extends android.app.Service
      implements android.media.MediaPlayer.OnPreparedListener, android.media.MediaPlayer.OnErrorListener, android.media.MediaPlayer.OnCompletionListener

  Created by Carolina Bonnin. Service para el reproductor de musica. Se queda ejecutandose en segundo plano, de manera que si salimos de la aplicacion la musica sigue sonando.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `MusicService.MusicBinder` Clase binder

    - ### Nested classes/interfaces inherited from class android.content.Context

      `android.content.Context.BindServiceFlags, android.content.Context.CreatePackageOptions, android.content.Context.ServiceName`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private android.os.IBinder` | `musicBind`
    `private static int` | `NOTIFY_ID`
    `private android.media.MediaPlayer` | `player`
    `private java.util.Random` | `rand`
    `private boolean` | `shuffle`
    `private int` | `songPosn`
    `private java.util.ArrayList<Song>` | `songs`
    `private java.lang.String` | `songTitle`

    - ### Fields inherited from class android.app.Service

      `START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, START_TASK_REMOVED_COMPLETE`

    - ### Fields inherited from class android.content.Context

      `ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_SHOWING_UI, BIND_TREAT_LIKE_ACTIVITY, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_REGISTER_PACKAGE, CONTEXT_RESTRICTED, COUNTRY_DETECTOR, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, ETHERNET_SERVICE, FINGERPRINT_SERVICE, HDMI_CONTROL_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, NETWORK_POLICY_SERVICE, NETWORK_SCORE_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, PERSISTENT_DATA_BLOCK_SERVICE, POWER_SERVICE, PRINT_SERVICE, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SIP_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TRUST_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, VOICE_INTERACTION_MANAGER_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_PASSPOINT_SERVICE, WIFI_RTT_SERVICE, WIFI_SCANNING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE`

    - ### Fields inherited from interface android.content.ComponentCallbacks2

      `TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MusicService()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getDur()`
    `int` | `getPosn()`
    `void` | `go()`
    `void` | `initMusicPlayer()` Metodo para incializar el reproductor de musica
    `boolean` | `isPng()`
    `android.os.IBinder` | `onBind(android.content.Intent intent)` Return the communication channel to the service.
    `void` | `onCompletion(android.media.MediaPlayer mp)` Called when the end of a media source is reached during playback.
    `void` | `onCreate()` Called by the system when the service is first created.
    `void` | `onDestroy()` Called by the system to notify a Service that it is no longer used and is being removed.
    `boolean` | `onError(android.media.MediaPlayer mp, int what, int extra)` Called to indicate an error.
    `void` | `onPrepared(android.media.MediaPlayer mp)` Called when the media file is ready for playback.
    `boolean` | `onUnbind(android.content.Intent intent)` Called when all clients have disconnected from a particular interface published by the service.
    `void` | `pausePlayer()`
    `void` | `playNext()` Metodo para pasar de cancion
    `void` | `playPrev()`
    `void` | `playSong()` Metodo para reproducir cancion
    `void` | `seek(int posn)`
    `void` | `setList(java.util.ArrayList<Song> theSongs)` Setter del listado de canciones
    `void` | `setShuffle()` Metodo para gestionar shuffle
    `void` | `setSong(int songIndex)`

    - ### Methods inherited from class android.app.Service

      `attach, dump, getApplication, onConfigurationChanged, onLowMemory, onRebind, onStartCommand, onTaskRemoved, onTrimMemory, startForeground, stopForeground, stopSelf, stopSelf, stopSelfResult`

    - ### Methods inherited from class android.content.ContextWrapper

      `attachBaseContext, bindService, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createApplicationContext, createConfigurationContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getBasePackageName, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDir, getDisplayAdjustments, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPrefsFile, getSystemService, getTheme, getThemeResId, getUserId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivitiesAsUser, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startInstrumentation, startIntentSender, startIntentSender, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver`

    - ### Methods inherited from class android.content.Context

      `getDrawable, getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### musicBind

          private final android.os.IBinder musicBind

    - #### NOTIFY_ID

          private static final int NOTIFY_ID

      See Also:
        Constant Field Values

    - #### player

          private android.media.MediaPlayer player

    - #### rand

          private java.util.Random rand

    - #### shuffle

          private boolean shuffle

    - #### songPosn

          private int songPosn

    - #### songs

          private java.util.ArrayList<Song> songs

    - #### songTitle

          private java.lang.String songTitle

  - ### Constructor Detail

    - #### MusicService

          public MusicService()

  - ### Method Detail

    - #### getDur

          public int getDur()

    - #### getPosn

          public int getPosn()

    - #### go

          public void go()

    - #### initMusicPlayer

          public void initMusicPlayer()

      Metodo para incializar el reproductor de musica

    - #### isPng

          public boolean isPng()

    - #### onBind

          public android.os.IBinder onBind(android.content.Intent intent)

      Description copied from class: `android.app.Service`
      Return the communication channel to the service. May return null if clients can not bind to the service. The returned `IBinder` is usually for a complex interface that has been described using aidl.

      Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

      Specified by:
        `onBind` in class `android.app.Service`
      Parameters:
        `intent` - The Intent that was used to bind to this service, as given to `Context.bindService`. Note that any extras that were included with the Intent at that point will not be seen here.
      Returns:
        Return an IBinder through which clients can call on to the service.

    - #### onCompletion

          public void onCompletion(android.media.MediaPlayer mp)

      Description copied from interface: `android.media.MediaPlayer.OnCompletionListener`
      Called when the end of a media source is reached during playback.
      Specified by:
        `onCompletion` in interface `android.media.MediaPlayer.OnCompletionListener`
      Parameters:
        `mp` - the MediaPlayer that reached the end of the file

    - #### onCreate

          public void onCreate()

      Description copied from class: `android.app.Service`
      Called by the system when the service is first created. Do not call this method directly.
      Overrides:
        `onCreate` in class `android.app.Service`

    - #### onDestroy

          public void onDestroy()

      Description copied from class: `android.app.Service`
      Called by the system to notify a Service that it is no longer used and is being removed. The service should clean up any resources it holds (threads, registered receivers, etc) at this point. Upon return, there will be no more calls in to this Service object and it is effectively dead. Do not call this method directly.
      Overrides:
        `onDestroy` in class `android.app.Service`

    - #### onError

          public boolean onError(android.media.MediaPlayer mp,
                                 int what,
                                 int extra)

      Description copied from interface: `android.media.MediaPlayer.OnErrorListener`
      Called to indicate an error.
      Specified by:
        `onError` in interface `android.media.MediaPlayer.OnErrorListener`
      Parameters:
        `mp` - the MediaPlayer the error pertains to
        `what` - the type of error that has occurred:
        - `MediaPlayer.MEDIA_ERROR_UNKNOWN`
        - `MediaPlayer.MEDIA_ERROR_SERVER_DIED`
        `extra` - an extra code, specific to the error. Typically implementation dependent.
        - `MediaPlayer.MEDIA_ERROR_IO`
        - `MediaPlayer.MEDIA_ERROR_MALFORMED`
        - `MediaPlayer.MEDIA_ERROR_UNSUPPORTED`
        - `MediaPlayer.MEDIA_ERROR_TIMED_OUT`
      Returns:
        True if the method handled the error, false if it didn't. Returning false, or not having an OnErrorListener at all, will cause the OnCompletionListener to be called.

    - #### onPrepared

          public void onPrepared(android.media.MediaPlayer mp)

      Description copied from interface: `android.media.MediaPlayer.OnPreparedListener`
      Called when the media file is ready for playback.
      Specified by:
        `onPrepared` in interface `android.media.MediaPlayer.OnPreparedListener`
      Parameters:
        `mp` - the MediaPlayer that is ready for playback

    - #### onUnbind

          public boolean onUnbind(android.content.Intent intent)

      Description copied from class: `android.app.Service`
      Called when all clients have disconnected from a particular interface published by the service. The default implementation does nothing and returns false.
      Overrides:
        `onUnbind` in class `android.app.Service`
      Parameters:
        `intent` - The Intent that was used to bind to this service, as given to `Context.bindService`. Note that any extras that were included with the Intent at that point will not be seen here.
      Returns:
        Return true if you would like to have the service's `Service.onRebind(android.content.Intent)` method later called when new clients bind to it.

    - #### pausePlayer

          public void pausePlayer()

    - #### playNext

          public void playNext()

      Metodo para pasar de cancion

    - #### playPrev

          public void playPrev()

    - #### playSong

          public void playSong()

      Metodo para reproducir cancion

    - #### seek

          public void seek(int posn)

    - #### setList

          public void setList(java.util.ArrayList<Song> theSongs)

      Setter del listado de canciones
      Parameters:
        `theSongs` - listado de canciones

    - #### setShuffle

          public void setShuffle()

      Metodo para gestionar shuffle

    - #### setSong

          public void setSong(int songIndex)