YouTube playsinline attribute

2019-06-14 14:21发布

window.player;
window.onYouTubeIframeAPIReady = function () {

  player = new YT.Player('player', {
    height: '200',
    width: '200',
    videoId: 'sdfsdfasd',
    playerVars: {'playsinline': 1},
    events: {
      'onReady': app.onPlayerReady,
      'onStateChange': app.onPlayerStateChange,
      'onError': app.onPlayerError
    }
  });

In my Cordova iOS app, I set YouTube iframe's playsinline attribute as 1 when the player is ready. However, when I play a video the player goes full screen. There is a post in Google group for YouTube API that says there's an inssue with playsinline attribute right now and it doesn't work.

The attribute works fine in a simulator, but it doesn't work on a real device. How should I fix this issue?

1条回答
We Are One
2楼-- · 2019-06-14 15:10

The problem was solved when I edited the source code inside webViewDidFinishLoad. From below

- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
    // Black base color for background matches the native apps
    theWebView.backgroundColor = [UIColor blackColor];
    return [super webViewDidFinishLoad:theWebView];
}

I added theWebView.allowsInlineMediaPlayback=YES;

- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
    // Black base color for background matches the native apps
    theWebView.backgroundColor = [UIColor blackColor];
    theWebView.allowsInlineMediaPlayback=YES; // <- added
    return [super webViewDidFinishLoad:theWebView];
}
查看更多
登录 后发表回答