ARCore - 在增强图像表面上播放 YouTube 视频
ARCore - playing YouTube video over augmented image surface
我正在尝试在使用 Google ARCore 库构建的 android 应用中通过增强图像目标表面播放来自 YouTube 的视频。
对于本地视频文件我没问题,我使用 MediaPlayer 对象如下:
MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.my_vid_local_file);
mediaPlayer.setSurface(texture.getSurface());
mediaPlayer.setLooping(true);
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
// Wait to set the renderable until the first frame of the video becomes available.
// This prevents the renderable from briefly appearing as a black quad before the video
// plays.
texture.getSurfaceTexture().setOnFrameAvailableListener(
(SurfaceTexture surfaceTexture) -> {
videoPlayerTexture.getNow(null).getMaterial().setExternalTexture("videoTexture", texture);
videoPlayerTexture.getNow(null).getMaterial().setFloat4("keyColor", CHROMA_KEY_COLOR);
mediaPlayerNode.setRenderable(videoPlayerTexture.getNow(null));
texture.getSurfaceTexture().setOnFrameAvailableListener(null);
});
} else {
mediaPlayerNode.setRenderable(videoPlayerTexture.getNow(null));
}
一切正常,但我很想从 YouTube 获取视频数据源,这样我就可以更改它而无需再次从商店下载我的应用程序。
我读了这个帖子:
关于在 YouTube API v3 中使用 RTSP link 但是当我将它作为我的 MediaPlayer 对象数据源时我得到一个异常。
我修改了如下代码:
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(context, Uri.parse("https://r8---sn-nx5cvox-hpay.googlevideo.com/videoplayback?expire=...and so on"));
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
// Wait to set the renderable until the first frame of the video becomes available.
// This prevents the renderable from briefly appearing as a black quad before the video
// plays.
texture.getSurfaceTexture().setOnFrameAvailableListener(
(SurfaceTexture surfaceTexture) -> {
videoPlayerTexture.getNow(null).getMaterial().setExternalTexture("videoTexture", texture);
videoPlayerTexture.getNow(null).getMaterial().setFloat4("keyColor", CHROMA_KEY_COLOR);
mediaPlayerNode.setRenderable(videoPlayerTexture.getNow(null));
texture.getSurfaceTexture().setOnFrameAvailableListener(null);
});
} else {
mediaPlayerNode.setRenderable(videoPlayerTexture.getNow(null));
}
}
});
mediaPlayer.prepare();
}catch(Exception e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
}
错误是:
D/MediaHTTPConnectionEx: [response code] STATUS CODE:403
I/native: tracking.cc:3027 no history. confidence : 1.0
D/MediaHTTPConnectionEx: [ResponseMessage]:Forbidden
E/MediaHTTPConnectionEx: MediaHTTPConnectionEx
com.lge.media.MediaHTTPConnectionEx 411 seekTo exception toString: java.io.IOException
D/MediaHTTPConnectionEx: connect
D/MediaHTTPConnectionEx: disconnecting
D/MediaHTTPConnectionEx: disconnected
D/MediaHTTPConnectionEx: [seekToEx] offset:0/mCurrentOffset:-1
D/MediaHTTPConnectionEx: proxy null port 0
I/native: tracking.cc:3027 no history. confidence : 1.0
D/MediaHTTPConnectionEx: [response code] STATUS CODE:403
D/MediaHTTPConnectionEx: [ResponseMessage]:Forbidden
E/MediaHTTPConnectionEx: MediaHTTPConnectionEx com.lge.media.MediaHTTPConnectionEx 411 seekTo exception toString: java.io.IOException
D/MediaHTTPConnectionEx: connect
D/MediaHTTPConnectionEx: disconnecting
D/MediaHTTPConnectionEx: disconnected
...
有一种方法可以使用 YouTube API KEY 还是我的方法完全错误?
谢谢指教
卡洛·塔西
YouTube 旨在使用自己的网页、通过嵌入式 HTML5 在另一个网页上或使用移动版 YouTube API 播放。
关键的共同点是它们都保留了 YouTube 品牌和外观。
有一些获取原始视频 URL 的方法示例,因此您可以直接播放它(例如 ),但是如果您使用原始视频 URL 和 MediaPlayer,你失去了 Youtube 的外观和感觉,通常这不是他们支持的东西。
如果您只想播放您有其他来源的视频或您可以自己托管的视频,那么您的方法看起来不错。
我正在尝试在使用 Google ARCore 库构建的 android 应用中通过增强图像目标表面播放来自 YouTube 的视频。 对于本地视频文件我没问题,我使用 MediaPlayer 对象如下:
MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.my_vid_local_file);
mediaPlayer.setSurface(texture.getSurface());
mediaPlayer.setLooping(true);
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
// Wait to set the renderable until the first frame of the video becomes available.
// This prevents the renderable from briefly appearing as a black quad before the video
// plays.
texture.getSurfaceTexture().setOnFrameAvailableListener(
(SurfaceTexture surfaceTexture) -> {
videoPlayerTexture.getNow(null).getMaterial().setExternalTexture("videoTexture", texture);
videoPlayerTexture.getNow(null).getMaterial().setFloat4("keyColor", CHROMA_KEY_COLOR);
mediaPlayerNode.setRenderable(videoPlayerTexture.getNow(null));
texture.getSurfaceTexture().setOnFrameAvailableListener(null);
});
} else {
mediaPlayerNode.setRenderable(videoPlayerTexture.getNow(null));
}
一切正常,但我很想从 YouTube 获取视频数据源,这样我就可以更改它而无需再次从商店下载我的应用程序。
我读了这个帖子:
我修改了如下代码:
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(context, Uri.parse("https://r8---sn-nx5cvox-hpay.googlevideo.com/videoplayback?expire=...and so on"));
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
// Wait to set the renderable until the first frame of the video becomes available.
// This prevents the renderable from briefly appearing as a black quad before the video
// plays.
texture.getSurfaceTexture().setOnFrameAvailableListener(
(SurfaceTexture surfaceTexture) -> {
videoPlayerTexture.getNow(null).getMaterial().setExternalTexture("videoTexture", texture);
videoPlayerTexture.getNow(null).getMaterial().setFloat4("keyColor", CHROMA_KEY_COLOR);
mediaPlayerNode.setRenderable(videoPlayerTexture.getNow(null));
texture.getSurfaceTexture().setOnFrameAvailableListener(null);
});
} else {
mediaPlayerNode.setRenderable(videoPlayerTexture.getNow(null));
}
}
});
mediaPlayer.prepare();
}catch(Exception e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
}
错误是:
D/MediaHTTPConnectionEx: [response code] STATUS CODE:403
I/native: tracking.cc:3027 no history. confidence : 1.0
D/MediaHTTPConnectionEx: [ResponseMessage]:Forbidden
E/MediaHTTPConnectionEx: MediaHTTPConnectionEx
com.lge.media.MediaHTTPConnectionEx 411 seekTo exception toString: java.io.IOException
D/MediaHTTPConnectionEx: connect
D/MediaHTTPConnectionEx: disconnecting
D/MediaHTTPConnectionEx: disconnected
D/MediaHTTPConnectionEx: [seekToEx] offset:0/mCurrentOffset:-1
D/MediaHTTPConnectionEx: proxy null port 0
I/native: tracking.cc:3027 no history. confidence : 1.0
D/MediaHTTPConnectionEx: [response code] STATUS CODE:403
D/MediaHTTPConnectionEx: [ResponseMessage]:Forbidden
E/MediaHTTPConnectionEx: MediaHTTPConnectionEx com.lge.media.MediaHTTPConnectionEx 411 seekTo exception toString: java.io.IOException
D/MediaHTTPConnectionEx: connect
D/MediaHTTPConnectionEx: disconnecting
D/MediaHTTPConnectionEx: disconnected
...
有一种方法可以使用 YouTube API KEY 还是我的方法完全错误?
谢谢指教
卡洛·塔西
YouTube 旨在使用自己的网页、通过嵌入式 HTML5 在另一个网页上或使用移动版 YouTube API 播放。
关键的共同点是它们都保留了 YouTube 品牌和外观。
有一些获取原始视频 URL 的方法示例,因此您可以直接播放它(例如 ),但是如果您使用原始视频 URL 和 MediaPlayer,你失去了 Youtube 的外观和感觉,通常这不是他们支持的东西。
如果您只想播放您有其他来源的视频或您可以自己托管的视频,那么您的方法看起来不错。