- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
I'm making an application that implements the picture in picture functionality in android.
When you click on the image, open a new activity with the picture in picture functionality.
自定义视频YoutubePlayer
public class VideoYoutubeView extends RelativeLayout {
private final static String TAG = VideoYoutubeView.class.getName();
@BindView(R.id.youtube_player)
YouTubePlayerView youTubePlayerView;
@BindView(R.id.movie_play)
TextView btnPlay;
@BindView(R.id.movie_forward)
TextView btnForward;
@BindView(R.id.movie_back)
TextView btnBack;
@BindView(R.id.text_time_movie)
TextView textTimeVideo;
@BindView(R.id.seek_progress_movie)
SeekBar seekBarMovie;
@BindView(R.id.text_down)
TextView btnDown;
private YouTubePlayer mPlayer;
private Handler mHandler = null;
private OnPipListener onPipListener;
public VideoYoutubeView(Context context) {
super(context);
}
public VideoYoutubeView(Context context, AttributeSet attrs) {
super(context, attrs);
this.init(context);
}
public VideoYoutubeView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.init(context);
}
public void setOnPipListener(@NonNull OnPipListener onPipListener) {
this.onPipListener = onPipListener;
}
public void init(Context context) {
View view = inflate(context, R.layout.youtube_view, this);
ButterKnife.bind(this, view);
this.mHandler = new Handler();
this.setTypeFace(context);
this.setUpVideoView();
}
private void setUpVideoView() {
final OnClickListener listener = view -> {
switch (view.getId()) {
case R.id.movie_play:
toggleMovie();
break;
case R.id.movie_back:
fastReview();
break;
case R.id.movie_forward:
fastForward();
break;
case R.id.text_down:
goToPip();
break;
}
};
this.btnPlay.setOnClickListener(listener);
this.btnForward.setOnClickListener(listener);
this.btnBack.setOnClickListener(listener);
this.btnDown.setOnClickListener(listener);
}
private void goToPip() {
if (this.onPipListener == null)
return;
this.onPipListener.goPiP();
}
public void hideControls() {
this.btnPlay.setVisibility(INVISIBLE);
this.btnDown.setVisibility(GONE);
this.textTimeVideo.setVisibility(GONE);
this.seekBarMovie.setVisibility(GONE);
}
public void showControls() {
this.btnPlay.setVisibility(VISIBLE);
this.btnDown.setVisibility(VISIBLE);
this.textTimeVideo.setVisibility(VISIBLE);
this.seekBarMovie.setVisibility(VISIBLE);
}
private void fastForward() {
}
private void fastReview() {
}
private void toggleMovie() {
if (this.mPlayer == null)
return;
if (this.mPlayer.isPlaying())
moviePause();
else
moviePlay();
}
private void moviePlay() {
if (this.mPlayer == null)
return;
this.mPlayer.play();
adjustStateMovie();
}
private void moviePause() {
if (this.mPlayer == null)
return;
this.mPlayer.pause();
adjustStateMovie();
}
private void adjustStateMovie() {
if (mPlayer == null)
return;
this.btnPlay.setText(mPlayer.isPlaying() ? R.string.iconPlay : R.string.iconPause);
}
private void setTypeFace(Context context) {
this.btnPlay.setTypeface(FontManager.getTypeface(context, FontManager.FONTAWESOME));
this.btnBack.setTypeface(FontManager.getTypeface(context, FontManager.FONTAWESOME));
this.btnForward.setTypeface(FontManager.getTypeface(context, FontManager.FONTAWESOME));
this.btnDown.setTypeface(FontManager.getTypeface(context, FontManager.FONTAWESOME));
}
public void initialize(String apiKey, String videoId) {
this.youTubePlayerView.initialize(apiKey, getOnInitializedListener(videoId));
}
private YouTubePlayer.OnInitializedListener getOnInitializedListener(String videoId) {
return new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer youTubePlayer, boolean wasRestored) {
if (null == youTubePlayer) return;
mPlayer = youTubePlayer;
currentTimeVideo();
// Start buffering
if (!wasRestored) {
youTubePlayer.cueVideo(videoId);
}
youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
youTubePlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);
// Add listeners to YouTubePlayer instance
youTubePlayer.setPlayerStateChangeListener(new YouTubePlayer.PlayerStateChangeListener() {
@Override
public void onAdStarted() {
}
@Override
public void onError(YouTubePlayer.ErrorReason arg0) {
}
@Override
public void onLoaded(String arg0) {
setSeekValue();
}
@Override
public void onLoading() {
}
@Override
public void onVideoEnded() {
}
@Override
public void onVideoStarted() {
currentTimeVideo();
}
});
youTubePlayer.setPlaybackEventListener(new YouTubePlayer.PlaybackEventListener() {
@Override
public void onBuffering(boolean arg0) {
}
@Override
public void onPaused() {
mHandler.removeCallbacks(runnable);
}
@Override
public void onPlaying() {
mHandler.postDelayed(runnable, 100);
currentTimeVideo();
}
@Override
public void onSeekTo(int arg0) {
mHandler.postDelayed(runnable, 100);
}
@Override
public void onStopped() {
mHandler.removeCallbacks(runnable);
}
});
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.d(TAG, "onInitializationFailure: Error initialize video youtube.");
}
};
}
private void currentTimeVideo() {
if (null == mPlayer) return;
String formattedTime = Util.formatTimeVideo(mPlayer.getDurationMillis() - mPlayer.getCurrentTimeMillis());
textTimeVideo.setText(formattedTime);
}
private void setSeekValue() {
if (mPlayer == null)
return;
this.seekBarMovie.setMax(mPlayer.getDurationMillis());
}
private Runnable runnable = new Runnable() {
@Override
public void run() {
currentTimeVideo();
mHandler.postDelayed(this, 100);
seekBarMovie.setProgress(mPlayer.getCurrentTimeMillis(), true);
}
};
public interface OnPipListener {
void goPiP();
}
}
Activity实现画中画功能:
public class VideoActivity extends YouTubeBaseActivity {
@BindView(R.id.movie_chat)
VideoYoutubeView movieChat;
private final PictureInPictureParams.Builder mPictureInPictureParamsBuilder =
new PictureInPictureParams.Builder();
private VideoYoutubeView.OnPipListener onPipListener = (this::setUpPip);
public static Intent getCallIntent(Context context, String messageConversation) {
Intent intent = new Intent(context, VideoActivity.class);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
ButterKnife.bind(this);
this.setUpView();
}
private void setUpView() {
this.movieChat.initialize("", "JRfuAukYTKg");
this.movieChat.setOnPipListener(onPipListener);
}
public void setUpPip() {
if (movieChat == null)
return;
this.movieChat.hideControls();
//Rational aspectRatio = new Rational(movieChat.getWidth(), movieChat.getHeight());
Rational aspectRatio = new Rational(20, 10);
mPictureInPictureParamsBuilder.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(mPictureInPictureParamsBuilder.build());
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
if (!isInPictureInPictureMode) {
// Show the video controls if the video is not playing
if (movieChat != null /*&& !movieChat.isPlaying()*/) {
movieChat.showControls();
}
}
}
}
有人可以帮助我使用 YoutubeAndroidPlayerApi 库实现此功能吗?
最佳答案
我认为您还必须在 Activity 中重写 onPause() -
@Override
public void onPause() {
// If called while in PIP mode, do not pause playback
if (isInPictureInPictureMode()) {
// Continue playback
...
} else {
// Use existing playback logic for paused Activity behavior.
...
}
}
关于java - YouTubePlayerView 画中画 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51861035/
好的,我正在为 Oreo 使用新的画中画 (PIP) 模式,并使用我计算的自定义宽高比: Display display = getWindowManager().getDefaultDisp
I'm making an application that implements the picture in picture functionality in android. When you
我正在构建要在 AWS (Linux) 上执行的 Python Lambda 函数代码。 我的开发机器不是 Linux。 如果我执行 pip install,我将获得与 Windows/MacOS 相
我对 Android TV 完全陌生,但对 PIP 概念的可行性进行了大量研究。不幸的是,我一直无法找到解决方案。我希望在我的 Android TV 应用程序上覆盖直播电视流。希望电视 Remote
自从我将包上传到 pypi 后,我的 setup.py 或 MANIFEST 中似乎缺少某些内容。 http://pypi.python.org/pypi/django-audiofield/ 当我尝
是否可以使用 ExoPlayer 在 Android 4.1+ 应用程序中实现画中画模式? iOS 的 AVPlayer 具有允许分离视频并将其显示在桌面上的内置功能,我找不到在 Android 4.
有什么区别 $ pip install --upgrade -r requirements.txt 和 $ pip install -r requirements.txt --upgrade ? 最佳
所以我正在尝试创建一个迷你 map /PIP。我有一个现有程序,其场景在 Qt Widget 中运行。我有一个类 NetworkViewer,它扩展了 CompositeViewer。在 Networ
如何在gstreamer中混合两个rtmp流? Src: nginx-rtmp 摄像头 - h.264/speex接收器:nginx-rtmp GStreamer 0.10 或 1.0 ------
我遇到了以下错误,我四处搜索,但找不到好的解决方法-请遇到此类错误并已解决的任何人。请帮忙。 File "c:\python27\lib\runpy.py", line 174, in _run_mo
目前我正在测试新的 CompactOverlay 模式,但似乎有一个问题,当运行应用程序时不在 Creators Update(例如 Anniversary Update)上。这是一段简化的代码 //
带有画中画 (PiP) 的 Safari HTML5 自定义视频 Controller 在 WWDC15 上,Apple 推出了 Safari 9 (适用于 MacOS 的 Safari 10),现在
我在 Android O 手机(各种三星版本)上使用 PIP 模式,效果很好。但是,如果我打开辅助功能模式,我会得到 java.lang.IllegalStateException·enterPict
我正在尝试弄清楚如何通过软件命令而不是 Remote 上的按钮触发 Google TV 中的画中画功能。据我所知,目前 API 中没有任何内容可以让我执行此操作。所以,有两个问题: 有人尝试过破解来实
这个问题在这里已经有了答案: pip cannot uninstall : "It is a distutils installed project" (6 个回答) 关闭2年前。 尝试安装 spyd
第一次使用pip,尝试使用the python-docs-samples tutorial library .当我运行“python -m pip install -r requirements.tx
我是一名优秀的程序员,十分优秀!