sk.baka.ambient.activity.main
Class PlayerController

java.lang.Object
  extended by sk.baka.ambient.activity.main.AbstractController
      extended by sk.baka.ambient.activity.main.PlayerController
All Implemented Interfaces:
SeekBar.OnSeekBarChangeListener, IApplicationListener, IPlaylistPlayerListener, ILibraryListener, IPlayerListener

public final class PlayerController
extends AbstractController
implements IPlaylistPlayerListener, IPlayerListener, IApplicationListener, ILibraryListener, SeekBar.OnSeekBarChangeListener

Controls the player view located on the MainActivity activity. This class is thread unsafe and all methods must be called from the message loop.

Author:
Martin Vysny

Nested Class Summary
 
Nested classes/interfaces inherited from class sk.baka.ambient.activity.main.AbstractController
AbstractController.Listener
 
Field Summary
 
Fields inherited from class sk.baka.ambient.activity.main.AbstractController
app, cycle, listener, mainActivity, mainView
 
Constructor Summary
PlayerController(MainActivity app)
          Creates the player controller.
 
Method Summary
 void buffered(byte percent)
          How much data is currently buffered.
 void clipboardChanged()
          The clipboard has been changed.
 void configChanged(ConfigurationBean config)
          The configuration was changed.
 void coverLoaded(TrackMetadataBean track)
          A cover for given track has been successfully downloaded.
 void destroy()
          The controller is about to be destroyed.
 void libraryUpdate(boolean updateStarted, boolean interrupted, boolean userNotified)
          Informs that the file rescan is complete and the database is updated.
 void lyricsLoaded(TrackMetadataBean track, List<LyrdbTrack> lyrics)
          A lyrics event.
 void offline(boolean offline)
          Informs that the application has entered an offline/online mode.
 void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch)
           
 void onStartTrackingTouch(SeekBar seekBar)
           
 void onStopTrackingTouch(SeekBar seekBar)
           
protected  void performZoom(boolean zoom)
          Zooms, or un-zooms the controller.
 void playbackStateChanged(PlayerStateEnum state)
          The playback state was changed.
 void playlistChanged(Interval target)
          Fired when the playlist changes - by removing a track, reshuffling etc.
 void radioNewTrack(String name)
          Track was switched while a radio is playing.
 void randomChanged(Random random)
          The play mode was changed.
 void repeatChanged(Repeat repeat)
          The play mode was changed.
 void started(String file, int duration, int currentPosition)
          Player started to play the song.
 void stateChanged(AppState state)
          The application state was changed.
 void stopped(String error, boolean errorMissing, TrackOriginEnum origin)
           The playback was stopped (not paused).
 void trackChanged(PlaylistItem item, boolean playing, int positionMillis)
          A new track was selected in the playlist.
 void trackPositionChanged(int position, boolean playing)
           A position in the track was changed.
 void update(Interval select)
          Reinitializes the underlying view.
protected  void visibilityChanged(boolean visible)
          Invoked when the component visibility changes.
 
Methods inherited from class sk.baka.ambient.activity.main.AbstractController
equals, flipVisibility, hashCode, hide, initButtonBar, initButtonBar, initButtonBar, isDestroyed, isVisible, isZoomed, onAction, setVisibility, show, zoom
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlayerController

public PlayerController(MainActivity app)
Creates the player controller.

Parameters:
app - the application instance
Method Detail

playbackStateChanged

public void playbackStateChanged(PlayerStateEnum state)
Description copied from interface: IPlaylistPlayerListener
The playback state was changed.

Specified by:
playbackStateChanged in interface IPlaylistPlayerListener
Parameters:
state - new playback state.

trackChanged

public void trackChanged(PlaylistItem item,
                         boolean playing,
                         int positionMillis)
Description copied from interface: IPlaylistPlayerListener
A new track was selected in the playlist.

Specified by:
trackChanged in interface IPlaylistPlayerListener
Parameters:
item - the new track, may be null - in this case the playback is stopped.
playing - if true then the track is already being played (or is about to be played).
positionMillis - the starting playback position in milliseconds.

visibilityChanged

protected void visibilityChanged(boolean visible)
Description copied from class: AbstractController
Invoked when the component visibility changes. By default does nothing.

Overrides:
visibilityChanged in class AbstractController
Parameters:
visible - new visibility flag.

trackPositionChanged

public void trackPositionChanged(int position,
                                 boolean playing)
Description copied from interface: IPlaylistPlayerListener

A position in the track was changed. This is only due to PlaylistPlayer.seek(int) - it is never invoked periodically as the playback progresses. This event is not invoked when a playback is started with non-zero start seek time.

Note that the playback may be paused.

Specified by:
trackPositionChanged in interface IPlaylistPlayerListener
Parameters:
position - the new position in milliseconds.
playing - if true then playback is activated, if false then the playback is paused. This event is not invoked when the playback is stopped.

randomChanged

public void randomChanged(Random random)
Description copied from interface: IPlaylistPlayerListener
The play mode was changed.

Specified by:
randomChanged in interface IPlaylistPlayerListener
Parameters:
random - new random value, never null.

repeatChanged

public void repeatChanged(Repeat repeat)
Description copied from interface: IPlaylistPlayerListener
The play mode was changed.

Specified by:
repeatChanged in interface IPlaylistPlayerListener
Parameters:
repeat - new repeat value, never null.

update

public void update(Interval select)
Description copied from class: AbstractController
Reinitializes the underlying view. Used when the view was not updated for a time and is about to be shown on screen. Default implementation does nothing.

Overrides:
update in class AbstractController
Parameters:
select - reset selection to this interval.

playlistChanged

public void playlistChanged(Interval target)
Description copied from interface: IPlaylistPlayerListener
Fired when the playlist changes - by removing a track, reshuffling etc.

Specified by:
playlistChanged in interface IPlaylistPlayerListener
Parameters:
target - the "target" (or the product) of the operation - for example for copy/move operations this interval contains added items, for delete operation the interval is empty. May be null if the target is not known. Semantically, the target should contain tracks that were 'produced' by the operation and they should be the target of the next operation. This implies that the playlist view should make these tracks appear selected.

configChanged

public void configChanged(ConfigurationBean config)
Description copied from interface: IApplicationListener
The configuration was changed.

Specified by:
configChanged in interface IApplicationListener
Parameters:
config - the configuration instance, must NOT be modified.

coverLoaded

public void coverLoaded(TrackMetadataBean track)
Description copied from interface: ILibraryListener
A cover for given track has been successfully downloaded. Note that if the cache size is set to a very small value the image may already be purged from the cache. To avoid this either set a sensible cache size value, e.g. 128kb, or turn off the image downloading by setting offline mode to true.

Specified by:
coverLoaded in interface ILibraryListener
Parameters:
track - the track.

libraryUpdate

public void libraryUpdate(boolean updateStarted,
                          boolean interrupted,
                          boolean userNotified)
Description copied from interface: ILibraryListener
Informs that the file rescan is complete and the database is updated. Invoked in Scanner thread.

Specified by:
libraryUpdate in interface ILibraryListener
Parameters:
updateStarted - if true then the library update just started. If false then the update finished.
interrupted - if true then the scan was interrupted.
userNotified - if true then the user is already notified about the library being updated.

clipboardChanged

public void clipboardChanged()
Description copied from interface: IApplicationListener
The clipboard has been changed.

Specified by:
clipboardChanged in interface IApplicationListener

radioNewTrack

public void radioNewTrack(String name)
Description copied from interface: IPlayerListener
Track was switched while a radio is playing.

Specified by:
radioNewTrack in interface IPlayerListener
Parameters:
name - the new track name.

onProgressChanged

public void onProgressChanged(SeekBar seekBar,
                              int progress,
                              boolean fromTouch)
Specified by:
onProgressChanged in interface SeekBar.OnSeekBarChangeListener

onStartTrackingTouch

public void onStartTrackingTouch(SeekBar seekBar)
Specified by:
onStartTrackingTouch in interface SeekBar.OnSeekBarChangeListener

onStopTrackingTouch

public void onStopTrackingTouch(SeekBar seekBar)
Specified by:
onStopTrackingTouch in interface SeekBar.OnSeekBarChangeListener

buffered

public void buffered(byte percent)
Description copied from interface: IPlayerListener
How much data is currently buffered. Applies only to online content, invoked with 0 when playing local tracks.

Specified by:
buffered in interface IPlayerListener
Parameters:
percent - how much the buffer is filled up. 0-100.

started

public void started(String file,
                    int duration,
                    int currentPosition)
Description copied from interface: IPlayerListener
Player started to play the song. Invoked shortly after the playback order is issued.

Specified by:
started in interface IPlayerListener
Parameters:
file - the file
duration - the file duration in ms. May be 0 if the stream is endless or the duration is not known.
currentPosition - current playback position, in ms.

stopped

public void stopped(String error,
                    boolean errorMissing,
                    TrackOriginEnum origin)
Description copied from interface: IPlayerListener

The playback was stopped (not paused). This may be caused by:

but never by

Specified by:
stopped in interface IPlayerListener
Parameters:
error - if not null then the player stopped because of an unspecified error.
errorMissing - if true then the error occurred because the file is missing.
origin - the track origin

lyricsLoaded

public void lyricsLoaded(TrackMetadataBean track,
                         List<LyrdbTrack> lyrics)
Description copied from interface: ILibraryListener
A lyrics event. Either lyrics for given track has been successfully downloaded or user needs to select one from given lyrics list.

Specified by:
lyricsLoaded in interface ILibraryListener
Parameters:
track - the track.
lyrics - if non-null then user needs to select the correct karaoke from this list. The list may be empty - in this case no karaoke files are available. If null then the karaoke file is available locally. If non-null and is empty then no karaoke files are available.

destroy

public void destroy()
Description copied from class: AbstractController
The controller is about to be destroyed. No invocations are performed after this call. The controller should release its resources, stop its activities etc. Make sure that you call super() if you override this method!

Overrides:
destroy in class AbstractController

offline

public void offline(boolean offline)
Description copied from interface: IApplicationListener
Informs that the application has entered an offline/online mode.

Specified by:
offline in interface IApplicationListener
Parameters:
offline - if true then we are currently offline. If false then we are online.

stateChanged

public void stateChanged(AppState state)
Description copied from interface: IApplicationListener
The application state was changed.

Specified by:
stateChanged in interface IApplicationListener
Parameters:
state - the state instance, must NOT be modified.

performZoom

protected void performZoom(boolean zoom)
Description copied from class: AbstractController
Zooms, or un-zooms the controller.

Specified by:
performZoom in class AbstractController
Parameters:
zoom - true zoom the controller in, false zoom the controller out.


Copyright © 2007-2008. All Rights Reserved.