Jplayer add a list of tracks in a dynamic (JS to extract list data from request as JS parameter)

Source: Internet
Author: User

Jplayer playlists Use the following:

1$ (document). Ready (function(){2 3     Newjplayerplaylist ({4Jplayer: "#jquery_jplayer_1",5Cssselectorancestor: "#jp_container_1"6     }, [7         {8Title: "Cro Magnon man",9MP3: "Http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3",TenOGA: "Http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg" One         }, A         { -Title: "Your Face", -MP3: "Http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3", theOGA: "Http://www.jplayer.org/audio/ogg/TSP-05-Your_face.ogg" -         }, -         { -Title: "Cyber Sonnet", +MP3: "Http://www.jplayer.org/audio/mp3/TSP-07-Cybersonnet.mp3", -OGA: "Http://www.jplayer.org/audio/ogg/TSP-07-Cybersonnet.ogg" +         }, A         { atTitle: "Tempered Song", -MP3: "Http://www.jplayer.org/audio/mp3/Miaow-01-Tempered-song.mp3", -OGA: "Http://www.jplayer.org/audio/ogg/Miaow-01-Tempered-song.ogg" -         }, -         { -Title: "Hidden", inMP3: "Http://www.jplayer.org/audio/mp3/Miaow-02-Hidden.mp3", -OGA: "Http://www.jplayer.org/audio/ogg/Miaow-02-Hidden.ogg" to         }, +         { -Title: "Lentement", theFreetrue, *MP3: "Http://www.jplayer.org/audio/mp3/Miaow-03-Lentement.mp3", $OGA: "Http://www.jplayer.org/audio/ogg/Miaow-03-Lentement.ogg"Panax Notoginseng         }, -         { theTitle: "Lismore", +MP3: "Http://www.jplayer.org/audio/mp3/Miaow-04-Lismore.mp3", AOGA: "Http://www.jplayer.org/audio/ogg/Miaow-04-Lismore.ogg" the         }, +         { -Title: "The Separation", $MP3: "Http://www.jplayer.org/audio/mp3/Miaow-05-The-separation.mp3", $OGA: "Http://www.jplayer.org/audio/ogg/Miaow-05-The-separation.ogg" -         }, -         { theTitle: "Beside Me", -MP3: "Http://www.jplayer.org/audio/mp3/Miaow-06-Beside-me.mp3",WuyiOGA: "Http://www.jplayer.org/audio/ogg/Miaow-06-Beside-me.ogg" the         }, -         { WuTitle: "Bubble", -Freetrue, AboutMP3: "Http://www.jplayer.org/audio/mp3/Miaow-07-Bubble.mp3", $OGA: "Http://www.jplayer.org/audio/ogg/Miaow-07-Bubble.ogg" -         }, -         { -Title: "Stirring of a Fool", AMP3: "Http://www.jplayer.org/audio/mp3/Miaow-08-Stirring-of-a-fool.mp3", +OGA: "Http://www.jplayer.org/audio/ogg/Miaow-08-Stirring-of-a-fool.ogg" the         }, -         { $Title: "Partir", theFreetrue, theMP3: "Http://www.jplayer.org/audio/mp3/Miaow-09-Partir.mp3", theOGA: "Http://www.jplayer.org/audio/ogg/Miaow-09-Partir.ogg" the         }, -         { inTitle: "Thin Ice", theMP3: "Http://www.jplayer.org/audio/mp3/Miaow-10-Thin-ice.mp3", theOGA: "Http://www.jplayer.org/audio/ogg/Miaow-10-Thin-ice.ogg" About         } the     ], { theSwfpath: ". /.. /dist/jplayer ", theSupplied: "OGA, MP3", +Wmode: "Window", -Usestateclassskin:true, theAutoblur:false,BayiSmoothplaybar:true, theKeyenabled:true the     }); -});
View Code

The background is struts2, and the returned data is a list containing the title and address.

For some reasons, instead of returning the JSON data, the list is taken from the request as the source of the data.

After a half-day trial, the list data in the request was dynamically added to the Jplayer playlist.

varStringlist= "["; <%//the function here is to add data from the list to Stringlist, Stinglist is used to dynamically build the parameters of the Jplay list.          for(intK=0;k<chapters.size (); k++) {Chapter Chapter=(Chapter) chapters.get (k); String Title1=Chapter.gettitle (); String Audio1=Chapter.getaudio (); %>stringlist+ = ' {title: '; Stringlist+ = ' "<%= title1%>" '; Stringlist+ = ', mp3: '; Stringlist+ = ' "<%= audio1%>" '; Stringlist+ = '}, '; <%          }          %>stringlist+="]";
View Code

It's a stupid way to stitch up a JSON string yourself ... Then when the parameters are used

$ (document). Ready (function(){    Newjplayerplaylist ({jplayer:"#jquery_jplayer_1", Cssselectorancestor:"#jp_container_1"}, eval (stringlist), {swfpath:"/js", supplied:"OGA, MP3", Wmode:"Window", Usestateclassskin:true, Autoblur:false, Smoothplaybar:true, AutoPlay:true, keyenabled:true    });});

Jplayer add a list of tracks in a dynamic (JS to extract list data from request as JS parameter)

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.