In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.