Android - YouTubePlayer Play Live

时间:2017-09-07 03:38:05

标签: android youtube youtube-api

我正在使用YouTube Android Player API来开展关于youtube live的项目。

public class YoutubeLiveActivity extends AppCompatActivity implements YouTubePlayer.OnInitializedListener {

private Context mContext = this;
YouTubePlayerSupportFragment youTubePlayerFragment;
private YouTubePlayer player;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_youtube_live);

    youTubePlayerFragment = (YouTubePlayerSupportFragment) getSupportFragmentManager().findFragmentById(R.id.youtube_fragment);
    youTubePlayerFragment.initialize(API_KEY, this);

}


private void playVideoAtSelection() {
    if (!(player == null)) {
        player.loadVideo(LIVE_ID);
    }
}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider arg0, YouTubePlayer arg1, boolean arg2) {
    this.player = arg1;

    playVideoAtSelection();

}

@Override
public void onInitializationFailure(YouTubePlayer.Provider arg0, YouTubeInitializationResult arg1) {

}

}

YouTubePlayer无法播放直播并显示“发生错误点击重试”。但是,它可以播放普通视频。请帮忙!!

**********更新了**********

我发现无法在YouTubePlayer上播放实时视频的问题。这是因为youtube版本的手机不是最新版本。在Play商店更新YouTube后,实时视频可以正常播放。

1 个答案:

答案 0 :(得分:0)

public User GetByEmail(string email)
{
    return _context.User.SingleOrDefault(x => x.Email == email);
}

public User GetByPostalCode(string postalCode)
{
    return _context.User.SingleOrDefault(x => x.Address.PostalCode == postalCode);
}