iOS Development Outreach-Audio processing (music Player 1

Source: Internet
Author: User

iOS Development Outreach-Audio processing (music player 1)

Description: This series of articles introduces the relevant knowledge points of audio processing by implementing a simple music player, needing to pay attention to the processing of many details.

First, adjust the structure of the project, import the necessary materialThe adjusted project structure is as follows:second, the new two controller(1) Create a new controller to display the music file list interface, which inherits from Uitableviewcontroller (2) to create a new controller to display the playback interface, which inherits from Uiviewcontroller (3) in storyboard, Remove the previous controller, replace it with a navigation controller, and set the Tableviewcontroller to associate with the previously created Controller classThird, the music file list controller in the basic interface construction(1) Create a new music file model based on the plist file: The code for the music model is as follows:

YYMusicModel.h file

1//2//  YYMusicModel.h 3//  20-Audio processing (music Player 1) 4//5//  Created by Apple on 14-8-13.6/  Copyright (c) 20 14 Yangyong. All rights reserved. 7//8  9 #import <foundation/foundation.h>10 @interface yymusicmodel:nsobject12/**13  *  song name 14
   */15 @property (copy, nonatomic) nsstring *name;16/**17  *  song big picture  */19 @property (copy, nonatomic) NSString *icon;20/**21  *  The file name of the song is  */23 @property (copy, nonatomic) nsstring *filename;24/**25  *< c15/> lyrics filename  */27 @property (copy, nonatomic) nsstring *lrcname;28/**29  * singer */31  @property ( Copy, nonatomic) nsstring *singer;32/**33  *  singer icon  */35 @property (copy, nonatomic) NSString * Singericon;36 @end
(2) The third-party framework part of the model using the dictionary to the relevant code is as follows: (3) Add a uiimageview category, adjust the singer's avatar (square-and-round) classification of the implementation code as follows: Uiimage+yy.h file
1 #import <uikit/uikit.h>2 3 @interface UIImage (YY) 4 + (Instancetype) Circleimagewithname: (NSString *) name BorderWidth: (cgfloat) borderWidth bordercolor: (Uicolor *) bordercolor;5 @end

UIIMAGE+YY.M file

 1 #import "Uiimage+yy.h" 2 #import <objc/message.h> 3 4 @implementation UIImage (YY) 5 + (Instancetype) circleimage Withname: (NSString *) name BorderWidth: (cgfloat) borderWidth bordercolor: (Uicolor *) bordercolor 6 {7//1. Loading the original 8 UI Image *oldimage = [UIImage imagenamed:name]; 9 10//2. Open context one by one cgfloat Imagew = oldImage.size.width + 2 * borderwidth;12 cgfloat Imageh = oldimage.size . Height + 2 * borderwidth;13 cgsize imageSize = Cgsizemake (Imagew, Imageh); uigraphicsbeginimagecontextwithoptio  NS (ImageSize, NO, 0.0); 15 16//3. Obtain the current context of cgcontextref CTX = Uigraphicsgetcurrentcontext (); 18 19// 4. Frame (great circle) [BorderColor set];21 cgfloat Bigradius = Imagew * 0.5; Circle Radius: CGFloat CenterX = Bigradius; Center of CGFloat centery = bigradius;24 Cgcontextaddarc (CTX, CenterX, CenterY, Bigradius, 0, M_PI * 2, 0); CG Contextfillpath (CTX); Draw a Circle 26 27//5. Small round cgfloat Smallradius = bigradius-borderwidth;29    Cgcontextaddarc (CTX, CenterX, CenterY, Smallradius, 0, M_PI * 2, 0); 30//cropping (the thing behind the painting will be affected by the clipping) Cgcontextclip (c TX); 32 33//6. Drawing [Oldimage Drawinrect:cgrectmake (BorderWidth, BorderWidth, OldImage.size.width, oldimage.si Ze.height)];35 36//7. Take fig. UIImage *newimage = Uigraphicsgetimagefromcurrentimagecontext (); 38 39//8 . End context Uigraphicsendimagecontext (); return newimage;43}44 @end
Use of classification: effect of Implementation: (4) A third-party framework is recommended to handle the code involved in the color:Iv. Implementation CodeYYMUSICSVIEWCONTROLLER.M file
 1//2//YYMUSICSVIEWCONTROLLER.M 3//20-Audio processing (music Player 1) 4//5//Created by Apple on 14-8-13. 6//Copyright (c) 2014 Yangyong. All rights reserved. 7//8 9 #import "YYMusicsViewController.h" #import "YYMusicModel.h" #import "MJExtension.h" #import "Uiimage+yy.h" #import "Colours.h" @interface Yymusicsviewcontroller () @property (nonatomic,strong) Nsarray *musics;17 @end18         @implementation YYMusicsViewController20 #pragma mark-lazy load-(Nsarray *) musics22 {(_musics==nil) {24 _musics=[yymusicmodel objectarraywithfilename:@ "Musics.plist"];25}26 return _musics;27}28 (void) ViewDidL oad31 {[Super viewdidload];33}35 #pragma mark-table view data source37/**38 * Total number of */40-(Nsinteg ER) Numberofsectionsintableview: (UITableView *) tableView41 {1;43}44/**45 * Number of rows per group */47-(Nsinteger) Tablev Iew: (UITableView *) TableView numberofrowsinsection: (nsinteger) section48 {* * return self.musics.count;50}51/**52 * cell53 */54 per row per group-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexPath55 {nsstring *[email protected] "ID"; UITableViewCell *cell=[tableview Dequeuereusablecel lwithidentifier:id];58 if (cell==nil) {Cell=[[uitableviewcell ALLOC]INITWITHSTYLE:UITABLEVIEWCELLSTYLESUBTI Tle reuseidentifier:id];60}61//Take out data model Yymusicmodel *model=self.musics[indexpath.row];63 Cell.textlabel . text=model.name;64 cell.detailtextlabel.text=model.singer;65 Cell.imageview.image=[uiimage circleImageWithName:m Odel.singericon borderwidth:1 bordercolor:[uicolor skybluecolor]];66 return cell;67}68/**69 * Set height per cell 70 */71 -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexPath72 {$ return 70;74}75 7 6/**77 * Cell's Click event */79-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) IndexPath8 0 {81//uncheck the line that was clicked [TaBleview Deselectrowatindexpath:indexpath animated:yes];83}85 @end 
Five, improveEncapsulation of Tableviewcell code: implementation:creates a new Yymusiccell class that inherits from UITableViewCell. The encapsulation code is as follows:YYMusicCell.h file
1//2//  YYMusicCell.h 3//  20-Audio processing (music Player 1) 4//5//  Created by Apple on 14-8-13.6/  Copyright (c) 201 4 years Yangyong. All rights reserved. 7//8  9 #import <uikit/uikit.h>10 @class yymusicmodel;11 @interface yymusiccell:uitableviewcell12 + (Instanc etype) Cellwithtableview: (UITableView *) tableview;13 @property (nonatomic,strong) Yymusicmodel *music;14 @end

YYMUSICCELL.M file

1//2//  YYMUSICCELL.M 3//  20-Audio processing (music Player 1) 4//5//  Created by Apple on 14-8-13.6/  Copyright (c) 201 4 years Yangyong. All rights reserved. 7//8  9 #import "YYMusicCell.h" #import "YYMusicModel.h" #import "Colours.h" #import "Uiimage+yy.h" @imple Mentation YYMusicCell15//Return a CELL16 + (instancetype) Cellwithtableview: (UITableView *) tableView17 {$     static NSString *[email protected] "ID";     Yymusiccell *cell=[tableview dequeuereusablecellwithidentifier:id];20     if (cell==nil) {         Cell=[[yymusiccell alloc]initwithstyle:uitableviewcellstylesubtitle reuseIdentifier:ID];22     }23     return cell;24}25-(void) Setmusic: (Yymusicmodel *) music27 {_music=music;29     self.textlabel.text=music.name;30     self.detailtextlabel.text=music.singer;31     self.imageview.image=[ UIImage circleImageWithName:music.singerIcon borderwidth:1 bordercolor:[uicolor skybluecolor]];32}33 @end

YYMUSICSVIEWCONTROLLER.M file

 1//2//YYMUSICSVIEWCONTROLLER.M 3//20-Audio processing (music Player 1) 4//5//Created by Apple on 14-8-13. 6//Copyright (c) 2014 Yangyong. All rights reserved. 7//8 9 #import "YYMusicsViewController.h" #import "YYMusicModel.h" #import "MJExtension.h" #import "YYMusicCell.h "@interface Yymusicsviewcontroller () @property (nonatomic,strong) nsarray *musics;16 @end17 @implementation YYMusicsViewController19 #pragma mark-lazy load-(Nsarray *) MUSICS21 {$ if (_musics==nil) {_musics=[yymusicmod El objectarraywithfilename:@ "musics.plist"];24}25 return _musics;26}27-(void) viewDidLoad29 {[Super V iewdidload];31}32 #pragma mark-table view data source34/**35 * Altogether how many groups of */37-(Nsinteger) Numberofsectionsintablevie W: (UITableView *) tableView38 {1;40}41/**42 * Number of lines per group */44-(Nsinteger) TableView: (UITableView *) TableView Numberofrowsinsection: (Nsinteger) section45 {self.musics.count;47}48/**49 * cell50 */51 per row for each group-(uitabLeviewcell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexPath52 {Yymusiccell *cel  L=[yymusiccell cellwithtableview:tableview];54 cell.music=self.musics[indexpath.row];55 return cell;56}57/**58 * Set height per cell */60-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexPath61 {70;63}64/**66 * Cell's Click event */68-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexPath69 {70//uncheck the line clicked [TableView Deselectrowatindexpath:indexpath animated:yes];72 73 }74 @end

Implementation results:

  

Vi. Additional Information

Attention to detail handling

(1) Classification of Uiimageview, square picture cut to circle

(2) Color processing, the recommended color processing frame in the article provides a large number of colors.

(3) Uncheck the cell that is clicked.

[TableView Deselectrowatindexpath:indexpath Animated:yes];

(4) Tableviewcell Package

iOS Development Outreach-Audio processing (music Player 1

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.