---
name: "tracks"
section: "3"
platform: "linux"
package: "libmtp"
version: "1.1.23-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/tracks"
---

# tracks(3)

The track management API.

## NAME

tracks - The track management API.

## SYNOPSIS

### Functions

**LIBMTP\_track\_t** \* **LIBMTP\_new\_track\_t** (void)\
 void **LIBMTP\_destroy\_track\_t** (**LIBMTP\_track\_t** \*)\
 **LIBMTP\_track\_t** \* **LIBMTP\_Get\_Tracklisting** (**LIBMTP\_mtpdevice\_t** \*)\
 **LIBMTP\_track\_t** \* **LIBMTP\_Get\_Tracklisting\_With\_Callback** (**LIBMTP\_mtpdevice\_t** \*, **LIBMTP\_progressfunc\_t** const, void const \*const)\
 **LIBMTP\_track\_t** \* **LIBMTP\_Get\_Tracklisting\_With\_Callback\_For\_Storage** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_progressfunc\_t** const, void const \*const)\
 **LIBMTP\_track\_t** \* **LIBMTP\_Get\_Trackmetadata** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const)\
 int **LIBMTP\_Get\_Track\_To\_File** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t, char const \*const, **LIBMTP\_progressfunc\_t** const, void const \*const)\
 int **LIBMTP\_Get\_Track\_To\_File\_Descriptor** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, int const, **LIBMTP\_progressfunc\_t** const, void const \*const)\
 int **LIBMTP\_Get\_Track\_To\_Handler** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **MTPDataPutFunc**, void \*, **LIBMTP\_progressfunc\_t** const, void const \*const)\
 int **LIBMTP\_Send\_Track\_From\_File** (**LIBMTP\_mtpdevice\_t** \*, char const \*const, **LIBMTP\_track\_t** \*const, **LIBMTP\_progressfunc\_t** const, void const \*const)\
 int **LIBMTP\_Send\_Track\_From\_File\_Descriptor** (**LIBMTP\_mtpdevice\_t** \*, int const, **LIBMTP\_track\_t** \*const, **LIBMTP\_progressfunc\_t** const, void const \*const)\
 int **LIBMTP\_Send\_Track\_From\_Handler** (**LIBMTP\_mtpdevice\_t** \*, **MTPDataGetFunc**, void \*, **LIBMTP\_track\_t** \*const, **LIBMTP\_progressfunc\_t** const, void const \*const)\
 int **LIBMTP\_Update\_Track\_Metadata** (**LIBMTP\_mtpdevice\_t** \*, **LIBMTP\_track\_t** const \*const)\
 int **LIBMTP\_Track\_Exists** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const)\
 int **LIBMTP\_Set\_Track\_Name** (**LIBMTP\_mtpdevice\_t** \*, **LIBMTP\_track\_t** \*, const char \*)\

## Detailed Description

## Function Documentation

### void LIBMTP\_destroy\_track\_t (LIBMTP\_track\_t \* track)

This destroys a track metadata structure and deallocates the memory used by it, including any strings. Never use a track metadata structure again after calling this function on it.

**Parameters**

*track* the track metadata to destroy.

**See also**

**LIBMTP\_new\_track\_t()**

References **LIBMTP\_track\_struct::album**, **LIBMTP\_track\_struct::artist**, **LIBMTP\_track\_struct::composer**, **LIBMTP\_track\_struct::date**, **LIBMTP\_track\_struct::filename**, **LIBMTP\_track\_struct::genre**, and **LIBMTP\_track\_struct::title**.

Referenced by **LIBMTP\_Get\_Tracklisting\_With\_Callback\_For\_Storage()**, and **LIBMTP\_Get\_Trackmetadata()**.

### int LIBMTP\_Get\_Track\_To\_File (LIBMTP\_mtpdevice\_t \* device, uint32\_t const id, char const \*const path, LIBMTP\_progressfunc\_t const callback, void const \*const data)

This gets a track off the device to a file identified by a filename. This is actually just a wrapper for the **LIBMTP\_Get\_Track\_To\_File() function.**

**Parameters**

*device* **a pointer to the device to get the track from.** \
 *id* **the track ID of the track to retrieve.** \
 *path* **a filename to use for the retrieved track.** \
 *callback* **a progress indicator function or NULL to ignore.** \
 *data* **a user-defined pointer that is passed along to the** progress **function in order to pass along some user defined data to the progress updates. If not used, set this to NULL.**

**Returns**

**0 if the transfer was successful, any other value means failure.**

**See also**

**LIBMTP\_Get\_Track\_To\_File\_Descriptor()**

**References LIBMTP\_Get\_File\_To\_File().**

### int LIBMTP\_Get\_Track\_To\_File\_Descriptor (LIBMTP\_mtpdevice\_t \* device, uint32\_t const id, int const fd, LIBMTP\_progressfunc\_t const callback, void const \*const data)

**This gets a track off the device to a file identified by a file descriptor. This is actually just a wrapper for the LIBMTP\_Get\_File\_To\_File\_Descriptor() function.**

**Parameters**

*device* **a pointer to the device to get the track from.** \
 *id* **the track ID of the track to retrieve.** \
 *fd* **a file descriptor to write the track to.** \
 *callback* **a progress indicator function or NULL to ignore.** \
 *data* **a user-defined pointer that is passed along to the** progress **function in order to pass along some user defined data to the progress updates. If not used, set this to NULL.**

**Returns**

**0 if the transfer was successful, any other value means failure.**

**See also**

**LIBMTP\_Get\_Track\_To\_File()**

**References LIBMTP\_Get\_File\_To\_File\_Descriptor().**

### int LIBMTP\_Get\_Track\_To\_Handler (LIBMTP\_mtpdevice\_t \* device, uint32\_t const id, MTPDataPutFunc put\_func, void \* priv, LIBMTP\_progressfunc\_t const callback, void const \*const data)

**This gets a track off the device to a handler function. This is actually just a wrapper for the LIBMTP\_Get\_File\_To\_Handler() function.**

**Parameters**

*device* **a pointer to the device to get the track from.** \
 *id* **the track ID of the track to retrieve.** \
 *put\_func* **the function to call when we have data.** \
 *priv* **the user-defined pointer that is passed to** put\_func**.** \
 *callback* **a progress indicator function or NULL to ignore.** \
 *data* **a user-defined pointer that is passed along to the** progress **function in order to pass along some user defined data to the progress updates. If not used, set this to NULL.**

**Returns**

**0 if the transfer was successful, any other value means failure.**

**References LIBMTP\_Get\_File\_To\_Handler().**

### LIBMTP\_track\_t \* LIBMTP\_Get\_Tracklisting (LIBMTP\_mtpdevice\_t \* device)

**THIS FUNCTION IS DEPRECATED. PLEASE UPDATE YOUR CODE IN ORDER NOT TO USE IT.**

**See also**

**LIBMTP\_Get\_Tracklisting\_With\_Callback()**

**References LIBMTP\_Get\_Tracklisting\_With\_Callback().**

### LIBMTP\_track\_t \* LIBMTP\_Get\_Tracklisting\_With\_Callback (LIBMTP\_mtpdevice\_t \* device, LIBMTP\_progressfunc\_t const callback, void const \*const data)

**This returns a long list of all tracks available on the current MTP device. Tracks include multimedia objects, both music tracks and video tracks. Typical usage:**

```
LIBMTP_track_t *tracklist;
tracklist = LIBMTP_Get_Tracklisting_With_Callback(device, callback, data);
while (tracklist != NULL) {
  LIBMTP_track_t *tmp;
  // Do something on each element in the list here...
  tmp = tracklist;
  tracklist = tracklist->next;
  LIBMTP_destroy_track_t(tmp);
}
```

**If you want to group your track listing by storage (per storage unit) or arrange tracks into folders, you must dereference the** storage\_id **and/or** parent\_id **field of the returned LIBMTP\_track\_t struct. To arrange by folders or files you typically have to create the proper trees by calls to LIBMTP\_Get\_Storage() and/or LIBMTP\_Get\_Folder\_List() first.**

**Parameters**

*device* **a pointer to the device to get the track listing for.** \
 *callback* **a function to be called during the tracklisting retrieveal for displaying progress bars etc, or NULL if you don't want any callbacks.** \
 *data* **a user-defined pointer that is passed along to the** progress **function in order to pass along some user defined data to the progress updates. If not used, set this to NULL.**

**Returns**

**a list of tracks that can be followed using the** next **field of the LIBMTP\_track\_t data structure. Each of the metadata tags must be freed after use, and may contain only partial metadata information, i.e. one or several fields may be NULL or 0.**

**See also**

**LIBMTP\_Get\_Trackmetadata()**

**References LIBMTP\_Get\_Tracklisting\_With\_Callback\_For\_Storage().**

**Referenced by LIBMTP\_Get\_Tracklisting().**

### LIBMTP\_track\_t \* LIBMTP\_Get\_Tracklisting\_With\_Callback\_For\_Storage (LIBMTP\_mtpdevice\_t \* device, uint32\_t const storage\_id, LIBMTP\_progressfunc\_t const callback, void const \*const data)

**This returns a long list of all tracks available on the current MTP device. Tracks include multimedia objects, both music tracks and video tracks. Typical usage:**

```
LIBMTP_track_t *tracklist;
tracklist = LIBMTP_Get_Tracklisting_With_Callback_For_Storage(device, storage_id, callback, data);
while (tracklist != NULL) {
  LIBMTP_track_t *tmp;
  // Do something on each element in the list here...
  tmp = tracklist;
  tracklist = tracklist->next;
  LIBMTP_destroy_track_t(tmp);
}
```

**If you want to group your track listing by storage (per storage unit) or arrange tracks into folders, you must dereference the** storage\_id **and/or** parent\_id **field of the returned LIBMTP\_track\_t struct. To arrange by folders or files you typically have to create the proper trees by calls to LIBMTP\_Get\_Storage() and/or LIBMTP\_Get\_Folder\_List() first.**

**Parameters**

*device* **a pointer to the device to get the track listing for.** \
 *storage\_id* **ID of device storage (if null, no filter)** \
 *callback* **a function to be called during the tracklisting retrieveal for displaying progress bars etc, or NULL if you don't want any callbacks.** \
 *data* **a user-defined pointer that is passed along to the** progress **function in order to pass along some user defined data to the progress updates. If not used, set this to NULL.**

**Returns**

**a list of tracks that can be followed using the** next **field of the LIBMTP\_track\_t data structure. Each of the metadata tags must be freed after use, and may contain only partial metadata information, i.e. one or several fields may be NULL or 0.**

**See also**

**LIBMTP\_Get\_Trackmetadata()**

**References LIBMTP\_track\_struct::filename, LIBMTP\_track\_struct::filesize, LIBMTP\_track\_struct::filetype, LIBMTP\_track\_struct::item\_id, LIBMTP\_destroy\_track\_t(), LIBMTP\_FILETYPE\_IS\_TRACK, LIBMTP\_new\_track\_t(), LIBMTP\_track\_struct::modificationdate, LIBMTP\_track\_struct::next, LIBMTP\_mtpdevice\_struct::params, LIBMTP\_track\_struct::parent\_id, LIBMTP\_track\_struct::storage\_id, and LIBMTP\_mtpdevice\_struct::usbinfo.**

**Referenced by LIBMTP\_Get\_Tracklisting\_With\_Callback().**

### LIBMTP\_track\_t \* LIBMTP\_Get\_Trackmetadata (LIBMTP\_mtpdevice\_t \* device, uint32\_t const trackid)

**This function retrieves the metadata for a single track off the device.**

**Do not call this function repeatedly! The track handles are linearly searched O(n) and the call may involve (slow) USB traffic, so use LIBMTP\_Get\_Tracklisting() and cache the tracks, preferably as an efficient data structure such as a hash list.**

**Parameters**

*device* **a pointer to the device to get the track metadata from.** \
 *trackid* **the object ID of the track that you want the metadata for.**

**Returns**

**a track metadata entry on success or NULL on failure.**

**See also**

**LIBMTP\_Get\_Tracklisting()**

**References LIBMTP\_track\_struct::filename, LIBMTP\_track\_struct::filesize, LIBMTP\_track\_struct::filetype, LIBMTP\_track\_struct::item\_id, LIBMTP\_destroy\_track\_t(), LIBMTP\_FILETYPE\_IS\_TRACK, LIBMTP\_new\_track\_t(), LIBMTP\_track\_struct::modificationdate, LIBMTP\_mtpdevice\_struct::params, LIBMTP\_track\_struct::parent\_id, LIBMTP\_track\_struct::storage\_id, and LIBMTP\_mtpdevice\_struct::usbinfo.**

### LIBMTP\_track\_t \* LIBMTP\_new\_track\_t (void )

**This creates a new track metadata structure and allocates memory for it. Notice that if you add strings to this structure they will be freed by the corresponding** LIBMTP\_destroy\_track\_t **operation later, so be careful of using strdup() when assigning strings, e.g.:**

```
LIBMTP_track_t *track = LIBMTP_new_track_t();
track->title = strdup(titlestr);
....
LIBMTP_destroy_track_t(track);
```

**Returns**

**a pointer to the newly allocated metadata structure.**

**See also**

**LIBMTP\_destroy\_track\_t()**

**Referenced by LIBMTP\_Get\_Tracklisting\_With\_Callback\_For\_Storage(), and LIBMTP\_Get\_Trackmetadata().**

### int LIBMTP\_Send\_Track\_From\_File (LIBMTP\_mtpdevice\_t \* device, char const \*const path, LIBMTP\_track\_t \*const metadata, LIBMTP\_progressfunc\_t const callback, void const \*const data)

**This function sends a track from a local file to an MTP device. A filename and a set of metadata must be given as input.**

**Parameters**

*device* **a pointer to the device to send the track to.** \
 *path* **the filename of a local file which will be sent.** \
 *metadata* **a track metadata set to be written along with the file. After this call the field** metadata-\>item\_id **will contain the new track ID. Other fields such as the** metadata-\>filename**,** metadata-\>parent\_id **or** metadata-\>storage\_id **may also change during this operation due to device restrictions, so do not rely on the contents of this struct to be preserved in any way.**

- •

  metadata-\>parent\_id **should be set to the parent (e.g. folder) to store this track in. Since some devices are a bit picky about where files are placed, a default folder will be chosen if libmtp has detected one for the current filetype and this parameter is set to 0. If this is 0 and no default folder can be found, the file will be stored in the root folder.**

- •

  metadata-\>storage\_id **should be set to the desired storage (e.g. memory card or whatever your device presents) to store this track in. Setting this to 0 will store the track on the primary storage.**

*callback* **a progress indicator function or NULL to ignore.** \
 *data* **a user-defined pointer that is passed along to the** progress **function in order to pass along some user defined data to the progress updates. If not used, set this to NULL.**

**Returns**

**0 if the transfer was successful, any other value means failure.**

**See also**

**LIBMTP\_Send\_Track\_From\_File\_Descriptor()**

**LIBMTP\_Send\_File\_From\_File()**

**LIBMTP\_Delete\_Object()**

**References LIBMTP\_Send\_Track\_From\_File\_Descriptor().**

### int LIBMTP\_Send\_Track\_From\_File\_Descriptor (LIBMTP\_mtpdevice\_t \* device, int const fd, LIBMTP\_track\_t \*const metadata, LIBMTP\_progressfunc\_t const callback, void const \*const data)

**This function sends a track from a file descriptor to an MTP device. A filename and a set of metadata must be given as input.**

**Parameters**

*device* **a pointer to the device to send the track to.** \
 *fd* **the filedescriptor for a local file which will be sent.** \
 *metadata* **a track metadata set to be written along with the file. After this call the field** metadata-\>item\_id **will contain the new track ID. Other fields such as the** metadata-\>filename**,** metadata-\>parent\_id **or** metadata-\>storage\_id **may also change during this operation due to device restrictions, so do not rely on the contents of this struct to be preserved in any way.**

- •

  metadata-\>parent\_id **should be set to the parent (e.g. folder) to store this track in. Since some devices are a bit picky about where files are placed, a default folder will be chosen if libmtp has detected one for the current filetype and this parameter is set to 0. If this is 0 and no default folder can be found, the file will be stored in the root folder.**

- •

  metadata-\>storage\_id **should be set to the desired storage (e.g. memory card or whatever your device presents) to store this track in. Setting this to 0 will store the track on the primary storage.**

*callback* **a progress indicator function or NULL to ignore.** \
 *data* **a user-defined pointer that is passed along to the** progress **function in order to pass along some user defined data to the progress updates. If not used, set this to NULL.**

**Returns**

**0 if the transfer was successful, any other value means failure.**

**See also**

**LIBMTP\_Send\_Track\_From\_File()**

**LIBMTP\_Delete\_Object()**

**References LIBMTP\_file\_struct::filename, LIBMTP\_track\_struct::filename, LIBMTP\_file\_struct::filesize, LIBMTP\_track\_struct::filesize, LIBMTP\_file\_struct::filetype, LIBMTP\_track\_struct::filetype, LIBMTP\_file\_struct::item\_id, LIBMTP\_track\_struct::item\_id, LIBMTP\_FILETYPE\_IS\_TRACK, LIBMTP\_Send\_File\_From\_File\_Descriptor(), LIBMTP\_Update\_Track\_Metadata(), LIBMTP\_file\_struct::next, LIBMTP\_mtpdevice\_struct::params, LIBMTP\_file\_struct::parent\_id, LIBMTP\_track\_struct::parent\_id, LIBMTP\_file\_struct::storage\_id, LIBMTP\_track\_struct::storage\_id, and LIBMTP\_mtpdevice\_struct::usbinfo.**

**Referenced by LIBMTP\_Send\_Track\_From\_File().**

### int LIBMTP\_Send\_Track\_From\_Handler (LIBMTP\_mtpdevice\_t \* device, MTPDataGetFunc get\_func, void \* priv, LIBMTP\_track\_t \*const metadata, LIBMTP\_progressfunc\_t const callback, void const \*const data)

**This function sends a track from a handler function to an MTP device. A filename and a set of metadata must be given as input.**

**Parameters**

*device* **a pointer to the device to send the track to.** \
 *get\_func* **the function to call when we have data.** \
 *priv* **the user-defined pointer that is passed to** get\_func**.** \
 *metadata* **a track metadata set to be written along with the file. After this call the field** metadata-\>item\_id **will contain the new track ID. Other fields such as the** metadata-\>filename**,** metadata-\>parent\_id **or** metadata-\>storage\_id **may also change during this operation due to device restrictions, so do not rely on the contents of this struct to be preserved in any way.**

- •

  metadata-\>parent\_id **should be set to the parent (e.g. folder) to store this track in. Since some devices are a bit picky about where files are placed, a default folder will be chosen if libmtp has detected one for the current filetype and this parameter is set to 0. If this is 0 and no default folder can be found, the file will be stored in the root folder.**

- •

  metadata-\>storage\_id **should be set to the desired storage (e.g. memory card or whatever your device presents) to store this track in. Setting this to 0 will store the track on the primary storage.**

*callback* **a progress indicator function or NULL to ignore.** \
 *data* **a user-defined pointer that is passed along to the** progress **function in order to pass along some user defined data to the progress updates. If not used, set this to NULL.**

**Returns**

**0 if the transfer was successful, any other value means failure.**

**See also**

**LIBMTP\_Send\_Track\_From\_File()**

**LIBMTP\_Delete\_Object()**

**References LIBMTP\_file\_struct::filename, LIBMTP\_track\_struct::filename, LIBMTP\_file\_struct::filesize, LIBMTP\_track\_struct::filesize, LIBMTP\_file\_struct::filetype, LIBMTP\_track\_struct::filetype, LIBMTP\_file\_struct::item\_id, LIBMTP\_track\_struct::item\_id, LIBMTP\_FILETYPE\_IS\_TRACK, LIBMTP\_Send\_File\_From\_Handler(), LIBMTP\_Update\_Track\_Metadata(), LIBMTP\_file\_struct::next, LIBMTP\_mtpdevice\_struct::params, LIBMTP\_file\_struct::parent\_id, LIBMTP\_track\_struct::parent\_id, LIBMTP\_file\_struct::storage\_id, LIBMTP\_track\_struct::storage\_id, and LIBMTP\_mtpdevice\_struct::usbinfo.**

### int LIBMTP\_Set\_Track\_Name (LIBMTP\_mtpdevice\_t \* device, LIBMTP\_track\_t \* track, const char \* newname)

**This function renames a single track. This simply means that the PTP\_OPC\_ObjectFileName property is updated, if this is supported by the device.**

**Parameters**

*device* **a pointer to the device that contains the file.** \
 *track* **the track metadata of the track to rename. On success, the filename member is updated. Be aware, that this name can be different than newname depending of device restrictions.** \
 *newname* **the new filename for this object.**

**Returns**

**0 on success, any other value means failure.**

**References LIBMTP\_track\_struct::filename, LIBMTP\_track\_struct::filetype, and LIBMTP\_track\_struct::item\_id.**

### int LIBMTP\_Track\_Exists (LIBMTP\_mtpdevice\_t \* device, uint32\_t const id)

**Helper function. This indicates if a track exists on the device**

**Parameters**

*device* **a pointer to the device to get the track from.** \
 *id* **the track ID of the track to retrieve.**

**Returns**

**TRUE (!=0) if the track exists, FALSE (0) if not**

**References LIBMTP\_mtpdevice\_struct::params.**

### int LIBMTP\_Update\_Track\_Metadata (LIBMTP\_mtpdevice\_t \* device, LIBMTP\_track\_t const \*const metadata)

**This function updates the MTP track object metadata on a single file identified by an object ID.**

**Parameters**

*device* **a pointer to the device to update the track metadata on.** \
 *metadata* **a track metadata set to be written to the file. notice that the** track\_id **field of the metadata structure must be correct so that the function can update the right file. If some properties of this metadata are set to NULL (strings) or 0 (numerical values) they will be discarded and the track will not be tagged with these blank values.**

**Returns**

**0 on success, any other value means failure. If some or all of the properties fail to update we will still return success. On some devices (notably iRiver T30) properties that exist cannot be updated.**

**References LIBMTP\_track\_struct::album, LIBMTP\_track\_struct::artist, LIBMTP\_track\_struct::bitrate, LIBMTP\_track\_struct::bitratetype, LIBMTP\_track\_struct::composer, LIBMTP\_track\_struct::date, LIBMTP\_track\_struct::duration, LIBMTP\_track\_struct::filetype, LIBMTP\_track\_struct::genre, LIBMTP\_track\_struct::item\_id, LIBMTP\_track\_struct::nochannels, LIBMTP\_mtpdevice\_struct::params, LIBMTP\_track\_struct::rating, LIBMTP\_track\_struct::samplerate, LIBMTP\_track\_struct::title, LIBMTP\_track\_struct::tracknumber, LIBMTP\_mtpdevice\_struct::usbinfo, LIBMTP\_track\_struct::usecount, and LIBMTP\_track\_struct::wavecodec.**

**Referenced by LIBMTP\_Send\_Track\_From\_File\_Descriptor(), and LIBMTP\_Send\_Track\_From\_Handler().**

## Author

**Generated automatically by Doxygen for libmtp from the source code.**
