How to use AVPlayer in multiple view and resume controls?

前端 未结 1 1996
你的背包
你的背包 2021-01-26 14:29

i create an app with xcode 4.6 on iOS 6.1 with a TabBar and 2 different tableView.

Each table view read a line form a file.plist and when tap on a row, you load a Detail

相关标签:
1条回答
  • 2021-01-26 15:15

    Solved, using this code:

    In my AppDelegate .h adding

    @interface AppDelegate : UIResponder <UIApplicationDelegate> {
    
        AVPlayer *MyPlayer;
    }
    
    @property (strong, nonatomic) AVPlayer *MyPlayer;
    

    in my AppDelegate .m inside didFinishLaunchingWithOptions adding

    [MySound superclass];
    

    Now can calling a method in all app with this code directly inside a .m file:

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    NSURL *url = [NSURL URLWithString:[saved objectForKey:@"link"]];
    appDelegate.MySound = [[AVPlayer alloc] initWithURL:url];
    [appDelegate.MySound setAllowsExternalPlayback:YES];
    [appDelegate.MySound setUsesExternalPlaybackWhileExternalScreenIsActive: YES];
    [appDelegate.MySound play];
    

    With this method now is possible controlling the AVPlayer evry where in the APP!!

    I Hope this Help any guys ;)

    0 讨论(0)
提交回复
热议问题