我正在开发一个youtube应用程序,在它里面我可以像这样添加时间戳。
所以我下一步要做的就是让youtube视频转到创建时间戳的特定时间点,通过单击textview。
这就是我目前所拥有的
package com.example.yukiv3.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.view.View;
import com.example.yukiv3.R;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.ui.views.YouTubePlayerSeekBar;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.ui.views.YouTubePlayerSeekBarListener;
import org.jetbrains.annotations.NotNull;
public class YTPlayerActivity extends AppCompatActivity {
public YouTubePlayerView ytPlayer;
public TextView videoTitle;
public int time = 0;
public TextView displayTime;
public Button button;
public YouTubePlayerSeekBar youTubePlayerSeekBar;
LinearLayout lin;
// public YTPlayerActivity(YouTubePlayerSeekBar youTubePlayerSeekBar) {
// this.youTubePlayerSeekBar = youTubePlayerSeekBar;
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ytplayer);
ytPlayer = findViewById(R.id.yt_player);
videoTitle = findViewById(R.id.video_title);
displayTime = findViewById(R.id.timeStamp);
youTubePlayerSeekBar = findViewById(R.id.youtube_player_seekbar);
lin = findViewById(R.id.linearLayout);
button = findViewById(R.id.button);
lin.removeAllViews();
Intent data = getIntent();
final String videoId = data.getStringExtra("video_id");
String video_title = data.getStringExtra("video_title");
ytPlayer.addYouTubePlayerListener(youTubePlayerSeekBar);
ytPlayer.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady(@NotNull final YouTubePlayer youTubePlayer) {
youTubePlayer.loadVideo(videoId, 0);
// doesnt do anything youTubePlayer.seekTo(time);
youTubePlayerSeekBar.setYoutubePlayerSeekBarListener(new YouTubePlayerSeekBarListener() {
@Override
public void seekTo(float time) {
youTubePlayer.seekTo(time);
}
});
}
@Override
public void onCurrentSecond(@NotNull YouTubePlayer youTubePlayer, float second) {
super.onCurrentSecond(youTubePlayer, second);
displayTime.setText(String.valueOf(second));
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final TextView textView = new TextView(YTPlayerActivity.this);
textView.setText(displayTime.getText());
final EditText editText = new EditText(YTPlayerActivity.this);
Button buttonView = new Button(YTPlayerActivity.this);
buttonView.setText("clear");
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = textView.getText().toString();
final Float f = Float.parseFloat(s);
editText.setText("Hello world!");
ytPlayer.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady(@NotNull final YouTubePlayer youTubePlayer) {
// youTubePlayer.loadVideo(videoId,0);
// doesnt do anything youTubePlayer.seekTo(time);
youTubePlayerSeekBar.setYoutubePlayerSeekBarListener(new YouTubePlayerSeekBarListener() {
@Override
public void seekTo(float time) {
youTubePlayer.seekTo(f);
}
});
}
@Override
public void onCurrentSecond(@NotNull YouTubePlayer youTubePlayer, float second) {
super.onCurrentSecond(youTubePlayer, second);
displayTime.setText(String.valueOf(second));
}
});
}
});
lin.addView(textView);
lin.addView(editText);
lin.addView(buttonView);
}
});
//this is where it would be set
videoTitle.setText(video_title);
}
}
我试着用
youtubepplayer.seekto(f);
方法,以便文本视图中的数值将在上述方法中实现,但这似乎不起作用。有人能帮我吗?
1条答案
按热度按时间gcuhipw91#
我想出了解决办法,
让我在视频中寻找所需的点