英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论