Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Music player in C language

Shulou Source: shulou.com Published: 2022-06-01 01:34:28 10月28日 Update

In this article, the editor introduces in detail "how to achieve a music player in C language". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to implement a music player in C language" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.

The example code is as follows:

# include#include#include#include # includetypedef struct node_ node_t;struct node_ {char* name;//gequming node_t * prev; node_t * next;}; node_t * head = NULL;int first=1;//diyicibofnagnode_t * cur = NULL;//dangqianbofangenum {STOP,PAUSE,PLAY}; int status = STOP;void List_init (void) {head = malloc (sizeof (node_t)); memset (head,0x00,sizeof (node_t)); head- > next = head- > prev=head } void list_insert (const char* name) {node_t * p = malloc (sizeof (node_t)); memset (preco 0x00 malloc sizeof (node_t)); p-> name = malloc (strlen (name) + 1); strcpy (p-> name,name); p-> next = head- > next; p-> prev = head; head- > next- > prev = p; head- > next = p } int menu (void) {printf ("* menu****\ n"); printf ("1.play/pause\ n"); printf ("2.next\ n"); printf ("3.prev\ n"); printf ("4.stop\ n"); printf ("5.exit\ n") Printf ("* *\ n"); list_show (); int choose = 4; do {printf (">"); scanf ("% d", & choose); if (choose > = 0 percent choosenext; while (paired head) {printf ("% s", p-> name); if (p==cur) printf ("/ dev/null | aplay 2 > / dev/null &", cur- > name) System (buf); first= 0; status= PLAY;} else {if (status==PLAY) {system ("killall-SIGSTOP aplay"); status= PAUSE;} else if (status==PAUSE) {system ("killall-SIGCONT aplay"); status= PLAY;}} void stop () {system ("killall-SIGKILL aplay"); first=1;} void next () {stop (); cur= cur- > next; if (cur==head) {cur= cur- > next;} playPause () } void prev () {stop (); cur= cur- > prev; if (cur==head) {cur= cur- > prev;} playPause ();} int main (int args,char * argv []) {List_init (); load_music (". / music/Music"); if (head- > nexttransition head) cur= head- > next; / / printf ("% s\ n", cur- > name); / / list_show (); do {int choose = menu (); switch (choose) {case 1: playPause (); Case 2: next (); break; case 3: prev (); break; case 4: stop (); break; case 0: printf ("thanks"); system ("killall-SIGKILL aplay"); exit (0); break; default: break; / / do nothing;}} while (1); return 0;}

The image of the effect of the example is as follows:

After reading this, the article "how to implement a music player in C language" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Player language music articles content examples propriety code pictures ideas effects new knowledge more steps knowledge knowledge points articles details industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology NVidia Shulou Tech Info MariaDB