iOS implements multimedia audio music player

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;">As the smartphone market becomes more active, the app has become colourful and diverse, making your app more appealing to multimedia technology inevitably. Make your app more colorful with controls like audio and video, and work with you today on basic audio Usage. This article only provides part of the code, if the question can download source View.</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;">The main function interface is as Follows:</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"></span></p></p> <ol> <ol> <li><strong><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;">First introduce the audio playback frame</span></strong></li> </ol> </ol><p><p><strong><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"><br></span></strong></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"> <strong>2, through the story version to build the interface, because this step is very simple, here does not explain. :</strong></span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"></span></p></p><p style="margin-left: 30px;"><p style="margin-left: 30px;"><strong><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;">3. Define variables to hold data and encapsulate the song information in the file into a model into the array</span></strong></p></p><pre><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">* Load Song data</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">@property (nonatomic,strong) Nsmutablearray</span></span>*<span style="color: #000000;"><span style="color: #000000;">dataarray;</span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">* Save cell Data Control color</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">@property (nonatomic,strong) Nsmutablearray</span></span>*<span style="color: #000000;"><span style="color: #000000;">cellarray;</span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">* Music that is currently playing</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">@property (nonatomic,strong) Jrplayerviewcontroller</span></span>*<span style="color: #000000;"><span style="color: #000000;">playervc;</span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">* Last music played</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">@property (nonatomic,strong) Nsindexpath</span></span>*<span style="color: #000000;"><span style="color: #000000;">front;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">#pragma</span></span>Mark-load data-(<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) _loaddata{nsstring</span></span>* Path=[[nsbundle mainbundle] Pathforresource:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">musics.plist</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">oftype:nil]; Nsarray</span></span>* array=<span style="color: #000000;"><span style="color: #000000;">[nsmutablearray arraywithcontentsoffile:path]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>(nsdictionary * DIC<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span><span style="color: #000000;"><span style="color: #000000;">Array) {jrmusic</span></span>*music=<span style="color: #000000;"><span style="color: #000000;">[jrmusic getmusicbydic:dic]; [self.dataarray addobject:music]; }}</span></span></pre><p style="margin-left: 30px;"><p style="margin-left: 30px;"><strong><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;">As follows:</span></strong></p></p><p><p></p></p><p style="margin-left: 30px;"><p style="margin-left: 30px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"><strong>4, Click to jump, load lyrics, here we need to parse the LRC lyrics, the LRC lyrics resolved to a time in seconds as key to the lyrics value of the dictionary and put into the array.</strong></span></p></p><pre><span style="color: #0000ff;"><span style="color: #0000ff;">#pragma</span></span>Mark-format the array for time as a dictionary-(nsarray *) _makedicwitharray: (nsarray *<span style="color: #000000;"><span style="color: #000000;">) Array {self.allkeys</span></span>=<span style="color: #000000;"><span style="color: #000000;">[nsmutablearray array]; Self.dataarray</span></span>=<span style="color: #000000;"><span style="color: #000000;">[nsmutablearray array];</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>(nsstring * STR<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span><span style="color: #000000;"><span style="color: #000000;">Array) { </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(str.length) {nsinteger</span> location</span>=[str rangeofstring:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">]</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">].location; NSString</span></span>* Front=[str substringtoindex:location+<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">1 Convert the first half into seconds</span></span>Nsmutablestring * fronttemp=<span style="color: #000000;"><span style="color: #000000;">[nsmutablestring stringwithstring:front]; [fronttemp replaceoccurrencesofstring:</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">[</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>Withstring:<span style="color: #800000;"><span style="color: #800000;">@""</span></span>Options:nscaseinsensitivesearch Range:nsmakerange (<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">, fronttemp.length)]; [fronttemp replaceoccurrencesofstring:</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">]</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>Withstring:<span style="color: #800000;"><span style="color: #800000;">@""</span></span>Options:nscaseinsensitivesearch Range:nsmakerange (<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">, fronttemp.length)]; Nsarray</span></span>* Temarray=[fronttemp componentsseparatedbystring:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">:</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]; CGFloat Key</span></span>=[[temarray firstobject] floatvalue]*<span style="color: #800080;"><span style="color: #800080;"></span> -</span>+<span style="color: #000000;"><span style="color: #000000;">[[temarray lastobject] floatvalue]; [self.allkeys addobject:@ (key)]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">2 intercept the latter part</span></span>NSString * Behind=[str substringfromindex:location+<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">]; [self.dataarray addobject:behind]; } } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>(<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>I=<span style="color: #800080;"><span style="color: #800080;">0</span></span>;i<<span style="color: #800080;"><span style="color: #800080;">Ten</span></span>; i++<span style="color: #000000;"><span style="color: #000000;">) {[self.dataarray addobject:</span></span><span style="color: #800000;"><span style="color: #800000;">@""</span></span><span style="color: #000000;"><span style="color: #000000;">]; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">nil; }</span></span></pre><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"><strong>5, According to the music playing time control text to scroll, in the music to play the time to set a timer, according to the time of the timer to get the current lyrics key, through Key can get the current lyrics, through the table scrolling way, the current lyrics display to the panel above</strong></span></p></p><pre><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Control Lyrics Scrolling</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Show{nsinteger Index</span></span>=<span style="color: #000000;"><span style="color: #000000;">[self getnowrows]; Nsindexpath</span></span>* Path=[nsindexpath Indexpathforrow:index Insection:<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">]; [self.tableview Scrolltorowatindexpath:path Atscrollposition:uitableviewscrollpositionmiddle animated:YES]; UITableViewCell</span></span>* cell=<span style="color: #000000;"><span style="color: #000000;">[self.tableview cellforrowatindexpath:path]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>(uitableviewcell * C<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span><span style="color: #000000;"><span style="color: #000000;">Self.allcell) {c.textlabel.textcolor</span></span>=<span style="color: #000000;"><span style="color: #000000;">[uicolor whitecolor]; C.textlabel.font</span></span>=[uifont systemfontofsize:<span style="color: #800080;"><span style="color: #800080;"></span> -</span><span style="color: #000000;"><span style="color: #000000;">]; } Cell.textLabel.textColor</span></span>=<span style="color: #000000;"><span style="color: #000000;">[uicolor greencolor]; Cell.textLabel.font</span></span>=[uifont boldsystemfontofsize:<span style="color: #800080;"><span style="color: #800080;"></span> -</span><span style="color: #000000;"><span style="color: #000000;">]; [cell.textlabel adjustsfontsizetofitwidth]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Setting time Changes</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(count%<span style="color: #800080;"><span style="color: #800080;">2</span></span>==<span style="color: #800080;"><span style="color: #800080;">0</span></span>&&<span style="color: #000000;"><span style="color: #000000;">[player Isplaying]) {nsstring</span></span>* times=<span style="color: #000000;"><span style="color: #000000;">[self getFomatByTime:player.currentTime]; Self.progress.startTime.text</span></span>=<span style="color: #000000;">times <span style="color: #000000;">; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Progress +1</span></span>self.progress.slider.value++<span style="color: #000000;"><span style="color: #000000;">; } Count</span></span>++<span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">End Loop</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(player.duration-player.currenttime<<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">) {[timer invalidate]; Timer</span></span>=<span style="color: #000000;"><span style="color: #000000;">nil; Self.progress.startTime.text</span></span>=<span style="color: #000000;"><span style="color: #000000;">[self Getfomatbytime:[player duration]]; } }</span></span></pre><p style="margin-left: 30px;"><p style="margin-left: 30px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"><strong>The effect is as Follows:</strong></span></p></p><p><p><span style="font-size: 14px;"><strong><span style="font-family: ‘Microsoft YaHei‘;"></span></strong></span></p></p><p><p></p></p><p style="margin-left: 30px;"><p style="margin-left: 30px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"><strong>6, Add the button information, through the button to control the previous song, the next and Pause. This work is done through xib,</strong></span></p></p><p><p></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"></span></p></p><p><p></p></p><p style="margin-left: 30px;"><p style="margin-left: 30px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 14px;"><strong>7, through the proxy method to achieve song switching</strong></span></p></p><pre><span style="color: #0000ff;"><span style="color: #0000ff;">#pragma</span></span>Mark-changesongsdelegate-(jrmusic *<span style="color: #000000;"><span style="color: #000000;">) chagesongswithflag: (nsinteger) flag{jrmusic</span></span>* music=<span style="color: #000000;"><span style="color: #000000;">nil;</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">if it is the previous page or the next page must meet not the first and last</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>((flag==<span style="color: #800080;"><span style="color: #800080;">2</span></span>&&self.front.row==self.dataarray.count-<span style="color: #800080;"><span style="color: #800080;">1</span></span>)|| (flag==<span style="color: #800080;"><span style="color: #800080;">1</span></span>&&self.front.row==<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">)) { </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">self.dataarray[self.front.row]; } </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Re-open</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(flag==<span style="color: #800080;"><span style="color: #800080;">2</span></span><span style="color: #000000;"><span style="color: #000000;">) {music</span></span>=self.dataarray[self.front.row+<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">]; Self.front</span></span>=[nsindexpath indexpathforrow:self.front.row+<span style="color: #800080;"><span style="color: #800080;">1</span></span>Insection:<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">]; }</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{music</span></span>=self.dataarray[self.front.row-<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">]; Self.front</span></span>=[nsindexpath indexpathforrow:self.front.row-<span style="color: #800080;"><span style="color: #800080;">1</span></span>Insection:<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">]; } </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">the <span style="color: #008000;">outside list shows red</span></span><span style="color: #000000;"><span style="color: #000000;">[self clear]; Jrtableviewcell</span></span>*cell= (jrtableviewcell *<span style="color: #000000;"><span style="color: #000000;">) [self.tableview cellForRowAtIndexPath:self.front]; Cell.titleLabel.textColor</span></span>=<span style="color: #000000;"><span style="color: #000000;">[uicolor redcolor]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">music;}</span></span></pre><p><p></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">To learn more about the small partners, you can click to <strong><span style="font-size: 18px;">view the source code</span></strong> , run the test yourself.</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">Inquiries or technical exchanges, Please join the official QQ group: (452379712)<br></span></p></p><p><p></p></p>Jerry Education<br>Source:<span style="color: #000000;"><span style="color: #000000;"><span style="color: #000000;">http://www.cnblogs.com/jerehedu/</span></span></span><br><span style="font-family: ‘Microsoft YaHei‘; color: #000000;"><span style="font-family: ‘Microsoft YaHei‘; color: #000000;">This article is the copyright of <span style="color: #000000;">Yantai Jerry Education Technology co., Ltd.</span> and the blog Park is shared, welcome reprint, but without the consent of the author must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility. </span></span><p><p>iOS implements multimedia audio music player</p></p></span>

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.