AVPlayer: Can't play video in table view cell

Hello everybody, I am currently using this code im my TableViewSource:

    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        var cell = (RFVideoTBC)tableView.DequeueReusableCell(RFVideoTBC.Identifier(), indexPath);

        var url = NSUrl.FromString("https://www.youtube.com/watch?v=tAGd-nev78g");

        AVPlayer player = AVPlayer.FromUrl(url);

        var playerViewController = new AVPlayerViewController();

        playerViewController.Player = player;
        playerViewController.View.Frame = new CoreGraphics.CGRect(16, 
                                                                  75, 
                                                                  cell.Frame.Width - 32,
                                                                  200);

        playerViewController.ShowsPlaybackControls = false;
        cell.AddSubview(playerViewController.View);

        player.Play();

        return cell;
    }

Player seems to be ready, the URL confirms to the HTTPS-protocol, player status is "ready to play".

But all I get is a black canvas:

What is wrong with my code? When I restart Xamarin, clean and rebuild the application, there is sometimes an
activity indicator working for 3 seconds, but the black canvas with the disabled play button returns.

Can't figure out why, tested playing a video on iOS 9 simulator and a my iPhone.

Best Answer

Answers

Sign In or Register to comment.