-
Notifications
You must be signed in to change notification settings - Fork 2
API Reference
ImoSPC provides methods giving you both basic playback controls as well as more “sophisticated” features such as fairly accurate time-telling, seeking, volume controls, getting SPC metadata, and detecting playback state changes.
Important: ImoSPC2 is currently in an alpha stage, so its API is subject to change.
(under construction)
The following optional parameters can be passed as the object options:
-
autostart : boolean: If
true
, then when open() is called, files will begin playing immediately after they are loaded. The default value isfalse
. -
autoplay : boolean: If
false
, then playlists will not automatically switch from one track to the next at the end of the track. - preferredRuntime : Runtime: If specified, then ImoSPC will try to load the specified runtime, if possible.
-
timeout : number: If specified, then the maximum amount of time in seconds to wait for ImoSPC to load before failing with
TIMEOUT
. The default value is 5 seconds.
Initializes the ImoSPC runtime so it can be used. The initialization is asynchronous, so listen for the init
event rather than doing anything immediately. If there is a failure, initerror
will be raised instead.
The following optional parameters can be passed as the object options:
- autostart : boolean: If defined, then overrides the current autostart setting.
- userdata : object: An arbitrary JavaScript object to be associated with the loaded track and playlist.
Loads SPC metadata from the specified SPC file or Zip archive.
To open a single SPC file out of an archive, use a fragment identifier, like so:
http://example.com/archive.zip#file.spc
The fragment identifier cannot contain hash characters; they must be URL-encoded. All special URL characters
Nested zip files are not supported; URLs such as the following will fail with BAD_URL
:
http://example.com/archive.zip#inner.zip#file.spc
Once the SPC metadata is loaded, the load
event will be raised. If the metadata can’t be loaded, then the loaderror
event will be raised instead.
Important: There are security restrictions on loading files across domains. In order to use cross-domain requests, you must first:
- Enable CORS on your server. This is for the HTML5 backend.
- Add a cross-domain policy file to your server. This is for the Flash backend.
Plays the specified track or playlist, starting at the specified time in seconds.
Pauses the currently playing track or playlist. If nothing was playing, then false
is returned; otherwise, true
is returned.
Resumes the previously playing track or playlist after it was paused. If nothing was playing, or if something was playing but not paused, then false
is returned; otherwise, true
is returned.
Stops the currently playing track or playlist. If nothing was playing, then false
is returned; otherwise, true
is returned.
Gets the playback position of the current track, in seconds, or -1 if nothing is playing.
Gets and sets the volume at which all SPC files will be played, respectively. volume must be in the range of [0, 1].
Gets the currently playing track, or null if nothing is playing.
Gets the currently playing playlist, or null if no playlist is playing.
If true
, then when metadata for a file is loaded, it will play automatically. The default value is false
.
If true
, then sequential playlists are enabled when calling Playlist.play
. Otherwise, only one track will be played. The default value is true
.
If true
, then the runtime will allow multiple SPC files to be playing simultaneously in separate browser tabs. The default value is false
.
Important: This can only affect instances of ImoSPC running on the same domain. Furthermore, an instance in one browser can’t pause an instance running in a different browser.
const version.major : number
const version.minor : number
const version.build : number
The version number of the loaded ImoSPC build.
const version.runtime : Runtime
Indicates what runtime, if any, is currently running.
Note: ImoSPC2 is currently in an alpha stage, so interpret 1.9.1 as "alpha."
Plays a solo track, starting at the specified time.
If the track is playing, then the track will relocate to the specified time, and return true
. Otherwise, returns false
.
Pauses the track and returns true
, if it is playing. Otherwise, returns false
. Also returns false
if the track is already paused.
Unpauses the track and returns true
, if it is paused. Otherwise, returns false
.
Stops the track and returns true
if it is playing.
Gets returns the time in seconds at which the track is playing, or -1
if the track is not playing or paused.
- Track.url : string: The complete URL from which the track was loaded.
-
Track.path : string: The path to the track within its parent archive, or
undefined
if the track wasn’t loaded from an archive. -
Track.archive : string: The complete URL of the archive from which the track was loaded, or
undefined
if the track wasn’t loaded from an archive. -
Track.title : string: The title of the track, or
undefined
if the SPC file doesn’t have a title in its metadata. - Track.length : number: The length of the track, in seconds.
-
Track.game : string: The name of the game the track is from, or
undefined
if the SPC file doesn’t have the name of the game in its metadata. -
Track.artist : string: The name of the artist who composed the track, or
undefined
if the SPC file doesn’t have the name of the track’s artist in its metadata. -
Track.publisher : string: The name of the publisher who published the game the track is from, or
undefined
if the SPC file doesn’t have the publisher name in its metadata. -
Track.copyright : number: The copyright year, or
undefined
if the SPC file doesn’t specify a copyright year in its metadata. - Track.osttitle : string: The title of the original sound track (OST) the track is from, if any.
- Track.ostdisc : number: The OST disc the track is from, if any.
-
Track.osttrack : string: The track number, if any, which may have an arbitrary ASCII character appended.
- Track.osttracknum : number: The track number, as a number. Since alphabetical sorting doesn’t work with numbers, this value should be used when sorting tracks manually.
- Track.osttrackchar : string: An optional character appended to the track number.
-
Track.userdata : object: The object that was passed to
ImoSPC.open()
, if any.
- Playlist.tracks : Array
- Playlist.length : number
- Playlist.userdata : object
- Error.SUCCESS: Self-explanatory.
- Error.UNKNOWN: An unknown error occurred.
- Error.INVALID_SPC: Attempted to load a bad SPC file.
- Error.INVALID_ZIP: Attempted to load a bad Zip archive.
- Error.EMPTY_ARCHIVE: Attempted to load an empty archive.
- Error.UNKNOWN_FILE_TYPE: Attempted to load a file that was neither an SPC file nor a Zip archive.
- Error.BAD_URL: The URL is malformed.
- Error.DOWNLOAD_ERROR: A download error occurred. If the error was an HTTP error, then the error message will be accompanied with the HTTP response code.
- Error.IO_ERROR: An I/O error occurred when trying to download or read a file.
- Error.PATH_NOT_FOUND: The requested file could not be found in the archive.
- Error.BROWSER_NOT_SUPPORTED: The user is using a browser that doesn’t support HTML5 and either doesn’t have Flash installed, or has the Flash plug-in disabled.
- Error.TIMEOUT: The initialization timeout has expired.
- Error.FLASHBLOCK: Flashblock-like behaviour was detected. The initialization is still pending, and will complete as soon as ImoSPC’s Flash backend is allowed to run.
- const Runtime.NONE: init() has not been called, or it has been called, but is still initializing.
- const Runtime.FLASH: ImoSPC is running through its Flash backend.
- const Runtime.HTML5: ImoSPC is running through its HTML5 backend.
- const PlaybackState.STOPPED
- const PlaybackState.PLAYING
- const PlaybackState.PAUSED
- const PlaybackState.BUFFERING
- const PlaybackState.LOADING
- const TrackSort.Title
- const TrackSort.Game
- const TrackSort.URL
- const TrackSort.Filename
- const TrackSort.Chronological
Raised when ImoSPC has been initialized successfully.
Raised when ImoSPC couldn’t be initialized. The event descriptor’s error
field will indicate what error occurred.
Raised when the metadata for a file is loaded. This event can be used even when autostart
is enabled.
Raised when either:
- The metadata for a file could not be loaded.
- A file could not be downloaded for playback.
Raised whenever ImoSPC’s playback state changes.
Adds and removes an event listener, respectively. Event listeners are called in the order they are added, and they are removed in the reverse order; i.e. when a single listener is added twice and removed once, the second listener will be removed.
listener
must be a function.