Ios 从应用程序Deligate UISplitViewController(MobileVLCKit)中的DetailViewController访问活动Mediaplayer

Ios 从应用程序Deligate UISplitViewController(MobileVLCKit)中的DetailViewController访问活动Mediaplayer,ios,objective-c,uisplitviewcontroller,Ios,Objective C,Uisplitviewcontroller,目前,我正在开发一款带有MobileVLCKit框架的视频流iOS应用程序。要在不同的发射器之间导航,我使用UISplitViewController。在我锁定iPad3的屏幕之前,这个应用程序运行良好。我调试了代码,知道播放器仍在后台运行。我必须访问媒体播放器属性(u mediaplayer)以在播放器退出或进入应用程序deligate的后台时停止播放器 我在www和stackoverflow上搜索过,但似乎有一小部分我没有看到或误解。如果有人能花点时间帮我找出问题,我会非常高兴 顺便说一句,

目前,我正在开发一款带有MobileVLCKit框架的视频流iOS应用程序。要在不同的发射器之间导航,我使用UISplitViewController。在我锁定iPad3的屏幕之前,这个应用程序运行良好。我调试了代码,知道播放器仍在后台运行。我必须访问媒体播放器属性(u mediaplayer)以在播放器退出或进入应用程序deligate的后台时停止播放器

我在www和stackoverflow上搜索过,但似乎有一小部分我没有看到或误解。如果有人能花点时间帮我找出问题,我会非常高兴

顺便说一句,是的,在使用了将近两年之后,我的第一篇帖子是:D

问题:如何访问appDeligate.m中的属性

AppDeligate.h

#import <UIKit/UIKit.h>

@class DetailViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    UISplitViewController *splitViewController;
}

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) DetailViewController *viewController;

@end
DetailViewController.h

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>

@property (strong, nonatomic) VLCMediaPlayer* _mediaplayer;
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UIView *movieView;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *indicator;

@end
#import <UIKit/UIKit.h>
#import <MobileVLCKit/MobileVLCKit.h>

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>

@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *tapGestureRecognizer;
@property (strong, nonatomic) VLCMediaPlayer* _mediaplayer;
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UIView *movieView;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *indicator;

@end
将splitViewController设置为@interface中的实例变量,然后更改:

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

    DetailViewController *thePlayer = [[splitViewController viewControllers] objectAtIndex:1];
    [thePlayer._mediaplayer stop];

    NSLog(@"Resign");
}

这是为我工作的最终代码。请随意使用

AppDelegate.h

#import <UIKit/UIKit.h>

@class DetailViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) DetailViewController *viewController;

@end
DetailViewController.h

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>

@property (strong, nonatomic) VLCMediaPlayer* _mediaplayer;
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UIView *movieView;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *indicator;

@end
#import <UIKit/UIKit.h>
#import <MobileVLCKit/MobileVLCKit.h>

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>

@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *tapGestureRecognizer;
@property (strong, nonatomic) VLCMediaPlayer* _mediaplayer;
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UIView *movieView;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *indicator;

@end

嘿,谢谢你的快速回答。我刚试过,但似乎不起作用。mediaplayer对象仍然为零。我将只更新DetailViewController*thePlayer=DetailViewController*navigationController.topViewController上面的代码;让navigationController成为一个实例变量,试试这个。伙计,你让我开心了!我不得不修改mediaplayer对象,现在它就像一个符咒。谢谢!
#import <UIKit/UIKit.h>
#import <MobileVLCKit/MobileVLCKit.h>

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>

@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *tapGestureRecognizer;
@property (strong, nonatomic) VLCMediaPlayer* _mediaplayer;
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UIView *movieView;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *indicator;

@end
#import "DetailViewController.h"

@interface DetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
@property (strong, nonatomic) UIBarButtonItem *barButton;
@end

@implementation DetailViewController

@synthesize _mediaplayer;

- (IBAction)handleTap:(UITapGestureRecognizer *)sender {
    [_barButton.target performSelector: _barButton.action withObject: _barButton];
}

#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
    NSLog(@"setDetailItem");
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;

        // Update the view.
        [self configureView];
    }
}

- (void)mediaPlayerStateChanged:(NSNotification *)aNotification
{
    VLCMediaPlayerState currentState = _mediaplayer.state;

    /* Playback opening */
    if (currentState == VLCMediaPlayerStateOpening) {
        [self.indicator startAnimating];
        NSLog(@"Openning");
    }

    /* or if playback ended */
    if (currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) {
        NSLog(@"Stopped");
        [self.indicator stopAnimating];
    }

    /* Playback buffering */
    if (currentState == VLCMediaPlayerStateBuffering) {
        NSLog(@"buffering");
        [self.indicator startAnimating];
    }

    /* Playback buffering */
    if (currentState == VLCMediaPlayerStatePlaying) {
        NSLog(@"Playing");
        [self.indicator stopAnimating];
    }
}

- (void)configureView
{
    NSLog(@"configureView");
    // Update the user interface for the detail item.

    if (self.detailItem) {

        self.imageView.image = nil;

        if(_mediaplayer.isPlaying) {
            // Stop active media
            [_mediaplayer stop];
        }

        // Set new url
        _mediaplayer.media = [VLCMedia mediaWithURL:[NSURL URLWithString:_detailItem]];

        // Play new media
        [_mediaplayer play];

        // Set radio image
        if ([_detailItem rangeOfString:@"239.192.1"].location != NSNotFound) {
            [self.imageView setImage:[[UIImage imageNamed:@"music.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]];
            self.imageView.contentMode = UIViewContentModeCenter;
        }
    }
}

- (void)viewDidLoad
{
    NSLog(@"viewDidLoad");
    [super viewDidLoad];

    // Hide navbar
    [[self navigationController] setNavigationBarHidden:YES animated:YES];

    // Show navbar
    [_barButton.target performSelector: _barButton.action withObject: _barButton afterDelay:1];

    // Background logo
    [self.imageView setImage:[[UIImage imageNamed:@"background.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]];
    self.imageView.contentMode = UIViewContentModeCenter;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Split view

- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:
(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
    return YES;
}

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
    _barButton = barButtonItem;
}
@end