Ios AVFoundation和多视图控制器

Ios AVFoundation和多视图控制器,ios,avfoundation,tabbar,Ios,Avfoundation,Tabbar,我正在学习ios开发,并开发一个音频播放器应用程序。因此,我需要创建一个音频播放器,该播放器可由应用程序的任何ViewController控制 到目前为止,我所做的是创建一个表视图并播放单击单元格的歌曲;还创建了AVfoundation音频播放器所需的控件,但所有这些控件都位于同一选项卡视图控制器中。 最后,我创建了一个带有5个表视图的选项卡栏控制器,我需要播放音频列表 有人能帮我找到从选项卡栏中的所有ViewController控制播放器的最佳方法吗 谢谢 上面是我在播放器所在的视图控制器中的

我正在学习ios开发,并开发一个音频播放器应用程序。因此,我需要创建一个音频播放器,该播放器可由应用程序的任何ViewController控制

到目前为止,我所做的是创建一个表视图并播放单击单元格的歌曲;还创建了AVfoundation音频播放器所需的控件,但所有这些控件都位于同一选项卡视图控制器中。 最后,我创建了一个带有5个表视图的选项卡栏控制器,我需要播放音频列表

有人能帮我找到从选项卡栏中的所有ViewController控制播放器的最佳方法吗

谢谢

上面是我在播放器所在的视图控制器中的代码,这个视图控制器有一个工作正常的表视图和播放器

@implementation ViewController {

    NSDictionary *Source01Details;
    NSArray *Source01Names;
    NSDictionary *Source02Details;
    NSArray *Source02Names;

    NSString *audioPath;
    NSURL *soundUrl;
    NSString *filename;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //Source 01
    NSURL *url1 = [[NSBundle mainBundle] URLForResource:@"data_group_01" withExtension:@"plist"];
    Source01Details = [NSDictionary dictionaryWithContentsOfURL:url1];
    Source01Names = Source01Details.allKeys;
    //Source 02
    NSURL *url2 = [[NSBundle mainBundle] URLForResource:@"data_group_02" withExtension:@"plist"];
    Source02Details = [NSDictionary dictionaryWithContentsOfURL:url2];
    Source02Names = Source02Details.allKeys;

    //START AUDIO
    // Construct URL to sound file
    filename = @"audioteste.wav";
    audioPath = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath],filename];
    soundUrl = [NSURL fileURLWithPath:audioPath];

    //Create audio player object and initialize with URL to sound
    _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
    self.isPlaying = NO;
    [self.audioProgressBar setProgress:0];
    //END AUDIO
}

- (void)updateProgressBar:(NSTimer *)timer {
    if ([_audioPlayer currentTime]==0) {
        [self.audioProgressBar setProgress:([_audioPlayer currentTime]/[_audioPlayer duration])];
        [self.topPlayButton setBackgroundImage:[UIImage imageNamed:@"PLAY"] forState:UIControlStateNormal];
        self.isPlaying = NO;

        //[[self rowDisplay] setText:@"Trocar esta linha por update de checkbox!"];

    } else {
        [self.audioProgressBar setProgress:([_audioPlayer currentTime]/[_audioPlayer duration])];
    }
}

- (IBAction)playButton:(id)sender {
    //[_audioPlayer play];
    if (self.isPlaying) // Music is currently playing
    {   [_audioPlayer pause];
        [self.topPlayButton setBackgroundImage:[UIImage imageNamed:@"PLAY"] forState:UIControlStateNormal];
        self.isPlaying = NO;
    }
    else // Music is currenty paused/stopped
    {   [_audioPlayer play];
        [self.topPlayButton setBackgroundImage:[UIImage imageNamed:@"PAUSE"] forState:UIControlStateNormal];
        self.isPlaying = YES;}
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.23 target:self selector:@selector(updateProgressBar:) userInfo:nil repeats:YES];
}

- (IBAction)pauseButton:(id)sender {
    [_audioPlayer stop];
    _audioPlayer.currentTime = 0;
    self.isPlaying = NO;
    [self.topPlayButton setBackgroundImage:[UIImage imageNamed:@"PLAY"] forState:UIControlStateNormal];
    [[self sectionDisplay] setText:@""];
    [self.audioProgressBar setProgress:0];
    [[self rowDisplay] setText:@"Escolha uma dica para ouvir"];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView    {
    return 2;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (section == 0){
        return @"Base para Emagrecimento";
    } else {
        return @"Supermercado";
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0){
        return Source01Details.count;
    } else {
        return Source02Details.count;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //create cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    //Faz as células terem bordas redondas
    CALayer *cellimagelayer = cell.layer;
    [cellimagelayer setCornerRadius:9 ];
    [cellimagelayer setMasksToBounds:YES];

    //Insere uma imagem
    //UIImage *playImage = [UIImage imageNamed:@"PLAY"];
    //[cell.imageView setImage:playImage];

    if (indexPath.section == 0) {
        cell.textLabel.text = Source01Names[indexPath.row] ;
        cell.detailTextLabel.text = Source01Details[Source01Names[indexPath.row]] ;
    } else {
        cell.textLabel.text = Source02Names[indexPath.row] ;
        cell.detailTextLabel.text = Source02Details[Source02Names[indexPath.row]] ;
    }
    //fill cell
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        filename = Source01Details[Source01Names[indexPath.row]] ;
        [[self sectionDisplay] setText: @"Base para Emagrecimento"];
        [[self rowDisplay] setText:Source01Names[indexPath.row]];
    } else {
        filename = Source02Details[Source02Names[indexPath.row]] ;
        [[self sectionDisplay] setText: @"Supermercado"];
        [[self rowDisplay] setText:Source02Names[indexPath.row]];
    }
    audioPath = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath],filename];
    soundUrl = [NSURL fileURLWithPath:audioPath];

    // Create audio player object and initialize with URL to sound
    _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];

    [_audioPlayer play];
    [self.topPlayButton setBackgroundImage:[UIImage imageNamed:@"PAUSE"] forState:UIControlStateNormal];
    self.isPlaying = YES;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.23 target:self selector:@selector(updateProgressBar:) userInfo:nil repeats:YES];

}

你能给我们一些代码告诉我们你在哪里被困,我们可以帮助你吗?我还没有在2ºviewcontroller中写入任何内容。