libnjb: The track playback (listening) API

libnjb 2.2.7

- Main Page
- Modules
- Data Structures
- Files
- Examples

Functions
The track playback (listening) API

## Functions
int | NJB_Play_Track (njb_t *njb, u_int32_t trackid)
int | NJB_Queue_Track (njb_t *njb, u_int32_t trackid)
int | NJB_Stop_Play (njb_t *njb)
int | NJB_Pause_Play (njb_t *njb)
int | NJB_Resume_Play (njb_t *njb)
int | NJB_Seek_Track (njb_t *njb, u_int32_t position)
int | NJB_Elapsed_Time (njb_t *njb, u_int16_t *elapsed, int *change)

## Detailed Description

## Function Documentation

int NJB_Elapsed_Time | ( | njb_t * | njb,
|  | u_int16_t * | elapsed,
|  | int * | change
| ) |  |

This function returns the elapsed time for the currently playing track on the device. Additionally, it signals if the track has changed, e.g. if the device has skipped to the next track in the queue.

Currently, it may only be determined if the currently playing track in the Nomad's play queue has changed (or ended) from a previous call to NJB_Elapsed_Time, because the indicator is that the elapsed time goes from a greater number to a lower number. Typically, when the first (zeroth) track in the play queue ends, the elapsed time is set to zero, and the change bit is set. However, if the zeroth track is the only track on the play queue, it must be more than 1 second long and NJB_Elapsed_Time must have been called at least once after 1 second actually has elapsed to register the change (song end) on a subsequent call to NJB_Elapsed_Time.

NOTE, the elapsed time will NOT always be zero when the change bit is set, as a call to NJB_Elapsed_Time may arrive late after a song has started.

NOTE, after NJB_Play_Track is called an immediate call NJB_Elapsed_Time will not indicate change, even if there was a track playing previously.

Obviously, this notification of change scheme is a flawed one, and some Nomad play queue management functions, such as finding out the actual trackid playing on the Nomad would be favored over this approach. One should not really rely too heavily on this approach.

Parameters

  njb | a pointer to the jukebox object that the track is playing on.
  elapsed | a pointer to a variable that will hold the number of elapsed seconds after the call to this function.
  change | a pointer to a variable that will hold 0 if the track has not changed, and something different from 0 if the track has changed.

Returns
  0 on success, -1 on failure.

Examples:
  cursesplay.c, and play.c.

References njb_struct::device_type, and NJB_DEVICE_NJB1.

int NJB_Pause_Play | ( | njb_t * | njb | ) |

This pauses the current playback of a track on the device.

Parameters

  njb | a pointer to the jukebox object to play the track on.

Returns
  0 on success, -1 on failure.

See Also
  NJB_Resume_Play()
  NJB_Stop_Play()

Examples:
  cursesplay.c.

int NJB_Play_Track | ( | njb_t * | njb,
|  | u_int32_t | trackid
| ) |  |

This starts playing a certain track on the device. This command will implicitly clear any pending or playing playback queue. You may queue up other songs using `NJB_Queue_Track()` while the first track is playing. The track on which you called `NJB_Play_Track()` will implicitly be placed first in the queue.

Parameters

  njb | a pointer to the jukebox object to play the track on.
  trackid | the track to play.

Returns
  0 on success, -1 on failure.

See Also
  NJB_Queue_Track()
  NJB_Stop_Play()
  NJB_Pause_Play()
  NJB_Seek_Track()
  NJB_Elapsed_Time()

Examples:
  cursesplay.c, and play.c.

References njb_struct::device_type, NJB_DEVICE_NJB1, and njb_verify_last_command().

int NJB_Queue_Track | ( | njb_t * | njb,
|  | u_int32_t | trackid
| ) |  |

This adds a track to the play queue of a device.

Parameters

  njb | a pointer to the jukebox object to play the track on.
  trackid | the track to add to the queue.

Returns
  0 on success, -1 on failure.

Examples:
  cursesplay.c, and play.c.

References njb_struct::device_type, NJB_DEVICE_NJB1, and njb_verify_last_command().

int NJB_Resume_Play | ( | njb_t * | njb | ) |

This resumes play of a track on the device after pause.

Parameters

  njb | a pointer to the jukebox object to resume the track on.

Returns
  0 on success, -1 on failure.

See Also
  NJB_Pause_Play()

Examples:
  cursesplay.c.

int NJB_Seek_Track | ( | njb_t * | njb,
|  | u_int32_t | position
| ) |  |

This seeks into an offset of the currenly playing track on the device. You can skip to an offset forward/backward in the currently playing file, given as milliseconds.

Parameters

  njb | a pointer to the jukebox object to stop the current playing track on.
  position | the position in the track file given as milliseconds. Offsets larger than the file length should not be used.

Returns
  0 on success, -1 on failure.

Examples:
  cursesplay.c.

int NJB_Stop_Play | ( | njb_t * | njb | ) |

This stops playback of a track on the device.

Parameters

  njb | a pointer to the jukebox object to stop the current playing track on.

Returns
  0 on success, -1 on failure.

See Also
  NJB_Pause_Play()

Examples:
  cursesplay.c, and play.c.

References njb_struct::device_type, and NJB_DEVICE_NJB1.