如何在Android Studio中使用起始时间和结束时间重复视频?

huangapple go评论71阅读模式
英文:

How to repeat video with start and end time in Android Studio?

问题

I'm getting error in Android Studio on second "cannot resolve symbol second" how to fix it so that it loops from 358 to 331 in this example?

package com.example.myapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;

public class FingerStretching extends AppCompatActivity {

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

        YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
        getLifecycle().addObserver(youTubePlayerView);

        youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
            String videoId = "mSZWSQSSEjE";
            int second = 0; // Add this line to create a local variable "second"
            @Override
            public void onReady(@NonNull YouTubePlayer youTubePlayer) {
                youTubePlayer.loadVideo(videoId, 331);
            }
            
            public void onCurrentSecond(@NonNull YouTubePlayer youTubePlayer) {
                second = (int) youTubePlayer.getCurrentSecond(); // Update the "second" variable with the current second
                if(second == 358) youTubePlayer.seekTo(331);
            }
        });
    }
}

tried creating local variable second

英文:

I'm getting error in Android Studio on second "cannot resolve symbol second" how to fix it so that it loops from 358 to 331 in this example?

package com.example.myapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;

public class FingerStretching extends AppCompatActivity {

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

        YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
        getLifecycle().addObserver(youTubePlayerView);

        youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
            String videoId = "mSZWSQSSEjE";
            @Override
            public void onReady(@NonNull YouTubePlayer youTubePlayer) {
                youTubePlayer.loadVideo(videoId, 331);
            }
            
            public void onCurrentSecond(@NonNull YouTubePlayer youTubePlayer) {
                if(second == 358) youTubePlayer.seekTo(331);
            }
        });



    }
}

tried creating local variable second

答案1

得分: 0

根据源代码onCurrentSecond 的签名是

override fun onCurrentSecond(youTubePlayer: YouTubePlayer, second: Float)

您没有重写它。它应该是

@Override
public void onCurrentSecond(@NonNull YouTubePlayer youTubePlayer, float second) {
    if(second >= 358) youTubePlayer.seekTo(331);
}

如果您在IDE中使用自动完成功能,就可以轻松避免这种错误。在AbstractYouTubePlayerListener内键入onC,应该会为onCurrentSecond提供自动完成选项,选择它应该会自动为您编写具有正确签名的重写函数。

英文:

According to the source code, the signature of onCurrentSecond is

override fun onCurrentSecond(youTubePlayer: YouTubePlayer, second: Float)

You are not overriding it. It should be

@Override
public void onCurrentSecond(@NonNull YouTubePlayer youTubePlayer, float second) {
    if(second >= 358) youTubePlayer.seekTo(331);
}

Such kind of error is easily avoidable if you make use of the auto complete feature in the IDE. Typing onC within the AbstractYouTubePlayerListener should give you auto complete option for onCurrentSecond, selecting it should automatically write the override function for you with correct signature.

huangapple
  • 本文由 发表于 2023年6月1日 10:35:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定