Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
static NSString *CellIdentifier=@"CellIdentifier";
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,AVAudioPlayerDelegate>
@property (nonatomic,strong) UITableView *myTableView;
@property (nonatomic,strong) NSMutableArray *musicPlayerName;
@property (nonatomic,strong) UIButton *startStopButton;
@property (nonatomic,strong) AVAudioPlayer *audioPlayer;
@end
@implementation ViewController
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=nil;
if ([tableView isEqual:self.myTableView]) {
cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (indexPath.section==0) {
cell.textLabel.text=[NSString stringWithFormat:@"%@",self.musicPlayerName[(long)indexPath.row]];
UIButton *playButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
playButton.frame = CGRectMake(200.0f, 5.0f, 75.0f, 30.0f);
playButton.tag = indexPath.row;
[playButton setTitle:@"Play" forState:UIControlStateNormal];
[cell addSubview:playButton];
[playButton addTarget:self action:@selector(playStop:)forControlEvents:UIControlEventTouchUpInside ];
}
}
return cell;
}
- (void)playStop:(UIButton *)sender
{
__unused UITableViewCell *cell = (UITableViewCell *) [self superviewOfType:[UITableViewCell class] forView:sender];
dispatch_queue_t dispatchQueue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
if ([sender.titleLabel.text isEqual:@"Stop"]) {
[self.audioPlayer stop];
[sender setTitle:@"Play" forState:UIControlStateNormal];
}else{
dispatch_async(dispatchQueue, ^(void){
[sender setTitle:@"Stop" forState:UIControlStateNormal];
NSBundle *mainBundle=[NSBundle mainBundle];
NSString *filePath=[mainBundle pathForResource:cell.textLabel.text ofType:@"mp3"] ;
NSData *fileData=[NSData dataWithContentsOfFile:filePath];
NSError *error=nil;
self.audioPlayer=[[AVAudioPlayer alloc] initWithData:fileData error:&error];
if (self.audioPlayer!=nil) {
self.audioPlayer.delegate=self;
if ([self.audioPlayer prepareToPlay] && [self.audioPlayer play]) {
} else {
/* Bşarısız */
}
}else{
/* AudioPlayer oluşturulmamış */
}
}); }
}
-(UIView *) superviewOfType:(Class) paramSuperViewClass forView:(UIView *) paramView {
if(paramView.superview!=nil){
if([paramView.superview isKindOfClass:paramSuperViewClass]){
return paramView.superview;
}else {
return [self superviewOfType:paramSuperViewClass forView:paramView.superview];
}
}
return nil;
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
if ([tableView isEqual:self.myTableView]) {
return 10;
}
return 0;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if ([tableView isEqual:self.myTableView]) {
switch (section) {
case 0:
return [self.musicPlayerName count];
break;
}
}
return 0;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.myTableView=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
[self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
self.myTableView.delegate=self;
self.myTableView.dataSource=self;
[self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
self.musicPlayerName=[[NSMutableArray alloc] initWithObjects:@"dereleri",@"erzincan",@"geceler",@"kalakaldim",@"malatya",@"mgna",@"tektas",@"titanic",@"yanar",@"yuzuk" ,nil];
[self.view addSubview:self.myTableView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team