|
#1
|
||||
|
||||
|
Libmtp is the software library used to handle MTP devices on Linux. When you experience connection problem using your MTP player on Linux, especially with media managers like Amarok, Banshee and the like, you often begin trouble-shooting with the command-line tools coming with libmtp. Their name are mtp-detect, mtp-tracks, mtp-files, mtp-getplaylist, etc. If they are not installed with the libmtp library on your system, you will get them by installing the libmtp-tools or mtp-tools package of your favorite distribution.
What is interesting is that the source code of these simple programs is available and is quite easy to understand even for a hobby programmer. It makes you want to write your own MTP manager program. ![]() Starting to explore the libmtp API is quite simple. Just install the libmtp-devel package of your distribution and open the HTML documentation at /usr/share/doc/packages/libmtp8/html/index.html (your path can vary). In the "Examples" tab you will get the source code of the small command-line programs suite. Your own C test program will include the libmtp.h headers file and the MTP device variable declaration and few libtmp API calls. To compile your mtp-cli-test.c program you can type Code:
gcc mtp-cli-test.c -lmtp -o mtp-cli-test 1 - Initialize the library 2 - Connect to your MTP device 3 - Perform some queries 4 - Release the connection Code:
#include <libmtp.h> ... LIBMTP_mtpdevice_t *mtpdev; LIBMTP_Init(); mtpdev = LIBMTP_Get_First_Device(); char *manufacturername = LIBMTP_Get_Manufacturername(mtpdev); char *modelname = LIBMTP_Get_Modelname(mtpdev); char *deviceversion = LIBMTP_Get_Deviceversion(mtpdev); /* Print or save the results as you like. */ LIBMTP_Release_Device(mtpdev); ... Have fun hacking with your MTP player! |
|
|
|||
|
|
|
#2
|
|||
|
|||
|
Thanks for the very informative post. This will definitely come in handy when I start working with libmtp in Arch Linux with C.
Cheers |
![]() |
| Tags |
| libmtp, linux, mtp, programming |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 09:08 PM.













Linear Mode
