开发者

how to play different audio files with same media player in a separate view- iphone sdk?

I've been trying and researching for countless hours but for some reason I just cant get my head around it and I know its a simple answer. Please Help!

I have a view with different buttons, -(ScrollViewController1)

the different buttons push in one view, -(b1ViewController) this view contains the media player,

In a nutshell, I cant figure out how to get the media player to play a different audio file depending on which button in the first view was pressed. I'm trying not to make a different view with a different media player for every button.

Could someone demonstrate it please so that I can understand it? Thanks a million. Heres the relevant code-

(ps- theres a reason for the tags, I didnt want to get too much into for the sake of asking a clear question and keeping it straight forward.)

@implementation ScrollViewController1

- (IBAction)pressedb1view {

    if (thebutton.tag==101) {

        [self performSelector:@selector(dismissb1pop:) withObject:nil afterDelay:0.1];
        b1view.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:b1view animated:YES];




}

    if (thebutton.tag==102) {

        [self performSelector:@selector(dismissb1pop:) withObject:nil afterDelay:0.1];
        b1view.hidesBottomBarWhenPushed开发者_运维技巧 = YES;
        [self.navigationController pushViewController:b1view animated:YES];

}

    if (thebutton.tag==103) {

        [self performSelector:@selector(dismissb1pop:) withObject:nil afterDelay:0.1];
        b1view.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:b1view animated:YES];

    }


}

etc, etc, etc....

in the next view which contains the mediaplayer I have-

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>


@interface b1ViewController : UIViewController {

    MPMoviePlayerController *moviePlayer;
    NSURL                                   *movieURL;


}

in the .m -

-(void)viewWillAppear:(BOOL)animated {

    [[self navigationController] setNavigationBarHidden:NO animated:YES];


    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"music1" ofType:@"mp3"];
    NSURL *url = [NSURL fileURLWithPath:urlStr];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [self.view addSubview:moviePlayer.view];
    moviePlayer.view.frame = CGRectMake(0, 0, 320, 40);  



    [moviePlayer play];

}

EDIT:

Im passing text from the first view to a uilabel on the second view using the following in the first view-

[b1view changeSiteText:@"im stuck here"];

in the second view Im doing this in the .h-

- (IBAction) changeSiteText:(NSString *)str;

and in the .m im doing this-

- (IBAction) changeSiteText:(NSString *)str{
    lblSiteTxt.text = str;

}

Is there a way to implement a similar method for the mediaplayer,??? maybe doing something like

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"mp3", str];  

Im stuck!!

Help!


Do you push the view or present it?

Add a method in the player class which when passed various arguments it plays the appropriate track or whatever. Then the different IBActions will invoke this method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜