youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
无法访问的声明:
public class TabFragment2 extends Fragment {
private FragmentActivity myContext;
YouTubePlayerSupportFragment youTubePlayerFragment;
private YouTubePlayer YPlayer;
private static final String YoutubeDeveloperKey = "xyz";
private static final int RECOVERY_DIALOG_REQUEST = 1;
@Override
public void onAttach(Activity activity) {
if (activity instanceof FragmentActivity) {
myContext = (FragmentActivity) activity;
}
super.onAttach(activity);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_tab_fragment2, container, false);
youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.youtube_fragment, youTubePlayerFragment).commit();
youTubePlayerFragment.initialize("AIzaS", new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider arg0, YouTubePlayer youTubePlayer, boolean b) {
if (!b) {
YPlayer = youTubePlayer;
YPlayer.setFullscreen(true);
YPlayer.loadVideo("2zNSgSzhBfM");
YPlayer.play();
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider arg0, YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
});
}
}
答案 0 :(得分:1)
按如下所示更改您的代码。您在所有内容之前都有return语句,因此它说的是无法访问的代码。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab_fragment2, container, false);
youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.youtube_fragment, youTubePlayerFragment).commit();
youTubePlayerFragment.initialize("AIzaS", new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider arg0, YouTubePlayer youTubePlayer, boolean b) {
if (!b) {
YPlayer = youTubePlayer;
YPlayer.setFullscreen(true);
YPlayer.loadVideo("2zNSgSzhBfM");
YPlayer.play();
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider arg0, YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
});
}
return view;
}
希望有帮助!!!只需在编写代码时检查一下这些内容,否则这些愚蠢的错误将花费您宝贵的时间;)