【问题标题】:Playing a youtube video in Mpmovieplayer or Mpmusicplayer ios在 Mpmovieplayer 或 Mpmusicplayer ios 中播放 youtube 视频
【发布时间】:2013-04-10 01:48:45
【问题描述】:

我想用 Mpmovieplayer 或 Mpmusicplayer 播放 youtube 视频。我想这样做是因为我需要让应用程序继续在后台模式下播放视频,而这在 uiwebview 中是完全不可能的。如果您能回答,请记住播放背景模式音频。在此先感谢:)

【问题讨论】:

    标签: iphone ios objective-c xcode mpmovieplayercontroller


    【解决方案1】:

    您可以使用 MPMovieplayerviewcontroller 并且它看起来像 iPhone 的默认播放器。

    这是我的答案:how to play live streaming from url for a camera that broadcasting live

    FOR BACKGROUND: 对于后台播放,请在 ViewDidLoad 方法中写入以下行 -

    NSError *setCategoryErr = nil;
        NSError *activationErr  = nil;
        [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr];
        [[AVAudioSession sharedInstance] setActive: YES error: &activationErr];
        [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
        UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
        newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
    

    并在您的info.plist 中进行一些小改动,如下图所示:

    【讨论】:

    • 感谢@Vishal + 1 的“直播..”:)
    【解决方案2】:

    我成功找到了 UIWebView 的解决方案,在看到这个 hack https://gist.github.com/romainbriche/2308668

    在 IO5/6 和 IOS7 上是不同的。

    您将遇到的问题是当应用程序进入后台时不停止声音。 我们在这里工作https://github.com/0xced/XCDYouTubeVideoPlayerViewController/issues/10#issuecomment-34252488

    我找到了一些解决方案,但并不完美。

    【讨论】:

      【解决方案3】:

      在 didFinishLaunchingWithOptions 中编写 Given below 代码

      AVAudioSession *audioSession = [AVAudioSession sharedInstance];
      NSError *setCategoryError = nil;
      
      BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
      if (!success) { NSLog(@"Error"); } else {NSLog(@"Success");}
      
      
      NSError *activationError = nil;
      success = [audioSession setActive:YES error:&activationError];
      if (!success) { NSLog(@"Error"); } else {NSLog(@"Success");}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-05
        • 2013-02-09
        • 2018-11-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多