Go Language programming Music library code

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

There are some code errors and omissions in the Go Language programming book, and here is a small piece of code that is modified and added.

---start, I also search a Baidu, mostly are the same, and in the Remove code block still have some problems (cannot be passed name).


All right!! Not much to say. All the code is shown below.

------------------------------------------------------------------------------------------------------

Paste the entry file first.

Mplayer.go

Package listen to Mainimport listen to listen to the "Bufio" listen to listen to "FMT" listen to listen to hear "OS" listen to hear "StrConv" listen to hear "strings" listen to listen to "mplayer/library" listen//Here is the directory structure Oh, Don't do it, SRC under the MPlayer directory of the library directory listen to hear "MPLAYER/MP" listen to//SRC under the MPlayer directory of the MP directory) Func listen to Handlelibcommands (tokens listen to []string) listen to {Listen and hear if listen to Len (tokens) Listen to < listen to 2 listen to listen to hear, listen, listen and hear the FMT. Println (' Listen, hear, listen, listen, listen, hear, hear following listen to commands listen to control listen to the listening player: Listen, listen, listen to the list-listen to the listen to the existing listen to the music listen to Lib Listen listen listen to listen to hear Lib listen to add listen to <name><artist><source><type > Listen-Listen to add listen to listen to music listen to listen to the music listen to the listening to listen to Lib listen to listen to the listen to hear the number of listening to the listen to the specified listen to the listen to listen to the listening to the music listen listen Listen, listen, listen, hear, listen and listen to the switch, listen to tokens[1, listen to the "list": Listen, listen, hear, hear and hear the FMT. PRINTLN ("Serial number, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, = listen to 0; listen to I listen < listen to lib. Len (); Listen to i++ listen to listen to listen to hear listen to listen to hear E, listen to listen to, listen to: = Hear lib. Get (i) Listen, listen, listen, listen, hear, listen and listen to the FMT. Printf ("%-4d listen to%-8s listen to%-10s listen to%-12s listen to the%-20s listen to listen to listen to listen to listen to hear%-5s\n", listen to I+1, listen to E. Id, listen to E. Name, listen to E. Artist, listen to E. Source, listen to E. Type) Listen, listen, listen, listen, hear, listen, hear, listen,//fmt. Println ("Listen", listen to I+1, listen ":", Listen to "Listen", listen to E. Id, listen to "Listen and listen", listen to E. Name, listen to "Listen and listen" and listen to E. Artist, listen to "Listen", listen to E. Source, listen to "Listen and listen" and listen to E. Type) Listen to listen and hearListen and listen to the case listen to "add": Listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, listen, hear, hear, hear, hear, hear, hear, hear, hear, hear, hear, hear, hear, hear, hear, hear, listen to, listen to, hear, hear, hear, hear, hear, hear, hear, hear, hear, hear, hear, ADD (&library. Musicentry{strconv. Itoa (ID), listen and listen listen listen listen to listen to listen to listen to listen to hear tokens[2], listen to tokens[3], listen to tokens[4], listen and hear listen to listen to listen to listening and listening listen to listen to the other listen to hear Listen, listen, listen, listen, hear, hear, hear, hear, and listen to the FMT. Println ("USAGE: Listen to Lib Listen add listen to <name><artist><source><type>") listen and listen listen and hear listen to listen to hear "listen" listen to listen to hear the hearing " Remove ": Listen and listen listen to hear if hear Len (tokens) Listen = = Listen to 3 listen to listen to listen to listen to listen to hear listening to listen to listen to hear the index, listen to listen: = Listen to StrConv. Atoi (tokens[2]) Listen, listen, hear, hear, hear, listen, hear//fmt. PRINTLN (index) Listen, listen, hear, hear, hear, hear, listen to Lib. Remove (index) Listen, listen, listen, listen and listen to the FMT. PRINTLN ("Serial number listen, listen, hear, listen to mp3_id listen, listen, hear, hear, listen and listen, hear, listen, listen, hear, listen, hear, hear, listen, listening and listening." * Listen, listen, hear, hear listen, listen, listen, listen, listen, listen, listen, hear, hear, listen, heard, hear, listen, listening and listening listen to listening and hearing: = listen to 0; listen I listen < Listen to Lib. Len (); Listen to i++ listen to listen to hear listen to listen to listen to listen to listen to hear E, listen to listen to: Get (i) Listen, listen, listen, listen, listen, hear, hear, hear, hear, and listen to the FMT. Printf ("%-4d listen to%-8s listen to%-10s listen to%-12s listen to the%-20s listen to listen to listen to listen to listen to hear%-5s\n", listen to I+1, listen to E. Id, listen to E. Name, listen to E. Artist, listen to E. Source, listen to E. Type) Listen and listen listen to hear listen to hear and listen to hear and listen to hear the other listen to listening to listen to listen to listen to listen to listen to listen to listen to listen to listen to listen to listen to listen to listen to hear listen to hear listen listen to hear hear listen to listening Println ("USAGE: Listen to Lib listen to remove <id>") Listen listen and listen to the default: Listen and listen to the FMT. Println ("Unrecognized listen to lib command:", listen to tokens[1]) listen to hear}}func listen to the Handleplaycommand (toKens listen to []string] listen to listen to hear if listen to Len (tokens) listen to! = Listen to 2 listen to listen and listen listen to and listen to the FMT. Println ("USAGE: Listen to play <name>") listen and listen listen and listen to listen to listen to listen to hear the E-listen: = Listen to lib. Find (Tokens[1]) listen to hear if listen to e listen to = = Listen to nil listen to listen to hear, listen, hear and hear the FMT. Println ("The Listening music", listen to tokens[1], listen to "does hear not listen to exist.") Listen, listen, listen, listen and listen to the MP. Play (E.source, listen E. Type)}var listen to Lib listen to *library. Musicmanagervar listen to int listen = Listen to 0func listen to main () Listen {Listen listen to lib listen = listen to the library. Newmusicmanager () Listen and listen to the FMT. Println (' Listen, hear, listen, listen, listen, hear, hear following listen to commands listen to control listen to the listening player: Listen, listen, listen to the list-listen to the listen to the existing listen to the music listen to Lib Listen listen listen to listen to hear Lib listen to add listen to <name><artist><source><type > Listen-Listen to add listen to listen to the music listen to listen to the music listen to the listen to the listen to listen to hear Lib listen to listen to listen to the listening to hear the listen to the listening < serial number > Listen-listen to the specified listen to the listen to the music listen to listen to the listen to Lib listen to listen to listen to listen to hear listening <name> listening to listen to the play listen to the listen to listen to the specified listen to the music listen to listen to listen to hear the listening Listen to E Listen-listen to quit listening to listen to listen to hear listen to listening to hear r: = Listen to Bufio. Newreader (OS. Stdin) listen and hear for listening to listen to the FMT. Print ("Enter Listen command-> listen") Listen listen to listen to listen to hear rawline, listen to _, listen to listen to: = Listen to R. ReadLine () Listen, listen, listen and listen to the line listen, listen, listen, hear, hear, listen, hear, hear, hear, listen to the line, listen, listen to listen to the "Q" Listening to the line (Rawline) Listen to the line listen to "E" hear {listen to listen to hear hear listen listening to hear hear listen listen listen to listen to hear listen listening to hear and hear listen and listen to hear tokens listening to listen to hear: = Listen to the strings. Split (line, listen "Listen") listen and hear hear and hear if listen to tokens[0] listen to = = Listen to "Lib" Listen to listen to hear (listen, listen, hear and hear handlelibcommands listen to listen to hear and hear) listen to hear the other listen to the IF listen to the tokens[0] listen to = = Listen to "Play" listen to { Listen, listen, hear, listen, hear, listen, hear, hear, listen to, listen to, hear and hear the Handleplaycommand (tokens) Listen, listen, hear, hear, hear, hear, listen, or listen to the FMT. Println ("Unrecognized listen to command:", listen to tokens[0]) listen and listen to listen to listen to hear}


Manager.go//In the Library directory under the MPlayer directory

Package Listen to Libraryimport listen (listen to hear "errors" listen to hear "FMT") type listen to Musicentry listen to the struct listen { Listen and listen to the ID listen to the string listen to listen to hear the name string listen to listen to hear artist listen to listen to hear the string listen to the listen to listen to hear the type listen to String}type listen to a string listen listen to the Musicmanager listen Listen to listen to musics listen to []musicentry}func listen to Newmusicmanager () listen to *musicmanager Listen {Listen to listen to hear the return to listen to &musicmanager{make (]musicentry, Listen to 0)}}func listen (M listen to *musicmanager) listen to Len () listen int Listen {Listen to listen to hear the return hear Len (m.musics)}func Listen (M listen to *musicmanager) hear get (index listen int) listen (Music listening * Musicentry, listen to err listen to error) Listen {Listen and listen if listen to the index listen < listen to 0 listen to | | Listen to the index listen to >= (m.musics) Listen {Listen to listen to hear hear listen to hear nil, listen to errors. New ("Index listen out listen to range.") Listen and listen to listen and hear//fmt. PRINTLN (m) listen to hear the return listen to &m.musics[index], listen to Nil}func hear (M listen *musicmanager) listen to find (name listen string) listen to *musicentry listen to { Listen to hear if listen to the m.musics listen to listen to listen to 0 listen to listen to hear (listen to hear) listen to listen to listen to listen to hear the listening to listen to hear and hear for listen to listening to: listen to listening to listen to listen to listen to listen to listen to listen to hear. Name hear = = Listen to listen to hear listen to hear (listen to, listen to, hear and hear) listen to listen to hear &m listen to listen to listen to hear the Nil}func listen and listen to hear the "listen" Musicentry Listen {Listen to listen to m.musics listen to listen to append (M.musics, listen to *music)}func listen (M listen to *musicmanager) listen to remove (index listen int) Listen to *musicentry listen to { Listen to hear if listen to index Listen < listen 0 Listen | | Listen to index > listen to Len (m.musics) Listen {Listen, listen, listen and listen to the FMT.PRINTLN ("Please re-select the deleted sequence number ...") Listen, hear, hear, listen, hear, hear, listen to Removedmusic listen, listen to the &m.musics[index-1, listen, listen, hear, hear, listen, or listen. Delete an element from an array slice listen and listen if you listen to the index listen < listen to Len ( M.musics listen to listen to the middle elements listen to listen to listen to hear listen to listen to hear m.musics listen to listen to append (M.musics[:index-1], listen to M.musics[index:] ...) Listen and listen to the other listen {listen//Listen to delete is the last element listen and listen listen to listen to hear//fmt. Println ("Delete the last One") listen and listen to listen to hear m.musics listen to listen to listen to hear the listening and hearing listen to listen to hear the return to hear the removedmusic}

Mp3.go The MP directory under the//mplayer directory

Package Listen to Mpimport listen (listen to "FMT" listen to listen to "time") type listen to Mp3player listen to the struct listen {Listen to listen to the stat listen int listen to hear the progress listen int} Type listen to Wavplayer listen to (listen to listen to the stat listen int listen to listen to progress listen to listen to hear the Int}func listen to hear (P listen *mp3player) listen to play (source listen to a string) listen {Listen to listen to the FMT. Println ("Playing listen to MP3 listen to music", listen to source) listen to listen to listen to hear p.progress listen to listen to 0 listen to listen to hear for the p.progress listen to < listen to 100 listen to listen to hear (listen to listen to listen to hear time.) Sleep (100 Listen * listen to Time.millisecond) listen//Listen to pretend to be playing listen and listen listen and listen to the FMT. Print (".") Listen, listen, listen, hear, hear, listen, p.progress, hear, hear, listen, listen to the FMT. 10 listen and hear. Println ("\nfinished listen to playing", listen to Source)}func Listen (P listen to *wavplayer) listen to play (source listen to string) hear {Listen and listen to the FMT. Sleep (100 Listen * listen to Time.millisecond) listen//Listen to pretend to be playing listen and listen listen and listen to the FMT. Print (".") Listen, listen, listen, hear, hear, listen, p.progress, hear, hear, listen, listen to the FMT. 10 listen and hear. Println ("\nfinished listen to playing", listen to Source)}


Play.go under the MP directory in the//mplayer directory

Package Listen Mpimport Listen to "FMT" type listen to player listen to interface Listen {Listen to listen to play (source listen string)}func listen to play (source, listen to Mtype listen to string) Listen { Listen and listen to the player listen to the Mtype listen to the switch listen to listen to listen to listen to hear the "MP3": Listen to hear listen to listen to hear, listen to listen to listen to listening to hear the &mp3player{, listen to hear the case listen to listen to listen to hear "WAV" wavplayer{} Listen and listen to the default: Listen, listen, listen and listen to the FMT. PRINTLN ("Unsupported listen to the music, listen to the type", listen to Mtype) listen and listen to listen and listen to listen to hear, hear and hear the p. Play (Source)}



-----------------------------------------------------------------------------------------------------

Please leave a message if there is any omission or code error. You are welcome to correct the corrections.

This article is from the "Goooood" blog, make sure to keep this source http://goooood.blog.51cto.com/5060201/1736072

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.