在后台播放的YoutubePlayer片段

时间:2018-12-15 19:00:27

标签: android-fragments youtube-api background-process youtube-data-api android-youtube-api

我收到了来自Google Play商店的消息,内容如下。

  

为明确起见,我们确定您的应用启用了YouTube视频的后台播放(按电源按钮并且屏幕关闭后,YouTube视频仍可以播放),这违反了YouTube API服务条款:

我的应用使用YouTubePlayerSupportFragment播放给定的视频。通过查看代码,我看不到如上所述的违反之处。

当我尝试在手机屏幕关闭模式下,我实际上没有收听任何视频播放。

我不确定是什么原因导致了违规。由于此应用已被删除。

请建议是否需要采取任何措施以遵守所有YouTube规则并被Play商店接受。 这是片段实现代码:

public class FragmentVideo extends  Fragment implements YouTubePlayer.OnInitializedListener {
    public static final String ARG_SECTION_NUMBER = "section_number";
    public static final String DEFAULT_VIDEO_LINK = "https://www.youtube.com/watch?v=dVzxrPKA8MM";
    public static final String DEFAULT_VIDEO_ID = "dVzxrPKA8MM";
    public static final String YOUTUBE_BASE_LINK ="www.youtube.com/watch?v=";
    private static final int RECOVERY_DIALOG_REQUEST = 1;

    public View rootView;
    public FragmentTransaction ft;
    public String videolink;
    public int loc;
    public YouTubePlayerSupportFragment youTubePlayerFragment;
    public static final String API_KEY = "XXXX-9Ku5SQ476uS9OtZYsWA";
    public static String VIDEO_ID = null;
    private Statelistener Statelistener;
    private eventlistener Events;


    public static FragmentVideo newInstance(String param1, String param2) {
        FragmentVideo fragment = new FragmentVideo();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    public FragmentVideo() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        Statelistener = new Statelistener();
        Events = new eventlistener();
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.fragment_video, container, false);
        TextView tv = (TextView) rootView.findViewById(R.id.videoDetails);

        videolink = getArguments().getString("VIDEOLINK");
        tv.setText("Playing Default video: " + videolink);              

        youTubePlayerFragment = new YouTubePlayerSupportFragment();
        youTubePlayerFragment.initialize(DeveloperKey.DEVELOPER_KEY, this);
        ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.fragment_youtube_player, youTubePlayerFragment);
        ft.commit();

        return rootView;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        // TODO Auto-generated method stub
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
              YouTubeInitializationResult errorReason) {
        if (errorReason.isUserRecoverableError()) {
                errorReason.getErrorDialog(super.getActivity(), RECOVERY_DIALOG_REQUEST).show();
            } else {
              //String errorMessage = String.format(getString(R.string.error_player), errorReason.toString());
              Toast.makeText(super.getActivity().getApplicationContext(), "error on initialization", Toast.LENGTH_LONG).show();
            }
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
              boolean wasRestored) {
        player.setPlayerStateChangeListener(Statelistener);
        player.setPlaybackEventListener(Events);
        if (!wasRestored) {
            player.cueVideo(VIDEO_ID);
         }      
    }

    @Override
    public void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
    }

    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    public void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
    }
}

0 个答案:

没有答案