YouTubePlayer api问题

时间:2018-02-09 04:06:57

标签: android youtube-api android-youtube-api

我在void BallisticObject::Explode() { int TileOverX = location.x / 64; int TileOverY = location.y / 64; if (TileOverX >= 0 && TileOverX < MAP_WIDTH && TileOverY >= 0 && TileOverY < MAP_HEIGHT) //if it's within bounds if (location.z <= Map[TileOverX][TileOverY]->myHeight + 1.0f) //if it's close to the ground { this->active = 0; Map[TileOverX][TileOverY]->myHeight -= 1.0f; //chip away at the ground //now look through the vector of integers (which are indices into the global ballistics vector) and find myself (one that matches my own index) for (int i = 0; i < Map[TileOverX][TileOverY]->Indices_of_Ballistic_Objects_Above_Me.size(); i++) { if (Map[TileOverX][TileOverY]->Indices_of_Ballistic_Objects_Above_Me[i] == myIndex) //found myself { //remove myself from the tile's list of ballistics object that are above it Map[TileOverX][TileOverY]->Indices_of_Ballistic_Objects_Above_Me.erase(i); break; } std::cout << "Error: ballistics object couldn't find itself in the tile's vector of indices!\n"; } } } 播放视频,视频播放正常。在播放视频时,如果我再次打开相同的活动并返回上一个MainActivity,那么youtube进度条会继续转动并且没有任何反应。我阅读了文档,但无法找到与此问题相关的任何内容。实际上,文档非常陈旧(2015年更新),2017年更新了MainActivity库。引导我走向正确的方向。

MainActivity.java

YouTubeAndroidPlayerApi

layout xml

public class MainActivity extends YouTubeBaseActivity
    implements YouTubePlayer.OnInitializedListener {

private String YOUTUBE_API_KEY = "api_key";
private YouTubePlayerView youtubePlayerView;

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_main);
    youtubePlayerView = findViewById(R.id.youtubePlayer);
    youtubePlayerView.initialize(YOUTUBE_API_KEY, this);

}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
    Log.w("youtube_activity", "onInitialization success");
    youTubePlayer.loadVideo("0KSOMA3QBU0");
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    Toast.makeText(this, "Initialization failure", Toast.LENGTH_SHORT);
}

public void onClick(View view) {
    startActivity(new Intent(this, MainActivity.class));
}
}

enter image description here

1 个答案:

答案 0 :(得分:0)

找到另一个youtubeplayeractivity时释放<Text>Lorem <Icon name="ios-book" size={30} color="#4F8EF7" /> Ipsum</Text> 的解决方案。当回到之前的youtubeplayeractivity reninitialized YouTubePlayer

YouTubePlayerView