我在android上使用vuforia SDK,我正在使用videoplayback示例代码。我想在运行时更改视频的源文件。要做到这一点,当我想加载一个新的视频文件时,首先我改变这样的视频文件名:
mMovieName[0] = Environment.getExternalStorageDirectory().getPath()+"/video1.mp4";
我通过从开头加载来检查视频文件的路径,这是正确的。 我把这一行放在这个方法中:
onQCARUpdate(State state)
以相等的时间步长运行。然后我用同样的方法加载这样的新视频:
mRenderer.requestLoad(0, mMovieName[0], 0, false);
最后它看起来像这样:
@Override
public void onQCARUpdate(State state)
{
if(loadNewVideo)
{
mMovieName[0] = Environment.getExternalStorageDirectory().getPath()+"/video1.mp4";
mRenderer.requestLoad(0, mMovieName[0], 0, false);
}
}
但问题是没有任何改变。初始视频在播放时继续播放,没有错误或崩溃。除了这些之外,我还应该做些什么,还是我完全离开了?
修改
我实际上并没有加载视频。我现在正在调用videoHelper的加载方法,但视频仍然没有改变。它只是冻结,我可以听到它的声音。
在VideoPlayback.java中,我添加了这个方法,我只需点击一下就可以在QCarUpdate内部调用:
private boolean changeVideo()
{
boolean result = true;
mMovieName[STONES] = Environment.getExternalStorageDirectory().getPath()+"/video1.mp4";
mRenderer.requestLoad(STONES, mMovieName[STONES], 0, false);
mRenderer.loadVideo(STONES);
return result;
}
还将此方法添加到VideoPlaybackRenderer.java(我刚刚从onSurfaceChanged复制了这些):
public void loadVideo(int i)
{
if (mVideoPlayerHelper[i] != null)
{
if (!mVideoPlayerHelper[i]
.setupSurfaceTexture(videoPlaybackTextureID[i]))
mCanRequestType[i] = MEDIA_TYPE.FULLSCREEN;
else
mCanRequestType[i] = MEDIA_TYPE.ON_TEXTURE_FULLSCREEN;
if (mLoadRequested[i])
{
mVideoPlayerHelper[i].load(mMovieName[i],
mCanRequestType[i], mShouldPlayImmediately[i],
mSeekPosition[i]);
mLoadRequested[i] = false;
}
}
}
视频的地址很好。我尝试加载它作为第一个视频,它播放正常。这两个视频都在SD存储上,我修改了VideoHelper.java以从SD加载。我也检查过,一旦我在目标外面点击它就会进入loadVideo。
修改
我必须在加载新视频之前卸载所以有效的是:
public void loadVideo(int i)
{
if (mVideoPlayerHelper[i] != null)
{
mVideoPlayerHelper[i].unload();
if (!mVideoPlayerHelper[i]
.setupSurfaceTexture(videoPlaybackTextureID[i]))
mCanRequestType[i] = MEDIA_TYPE.FULLSCREEN;
else
mCanRequestType[i] = MEDIA_TYPE.ON_TEXTURE_FULLSCREEN;
if (mLoadRequested[i])
{
mVideoPlayerHelper[i].load(mMovieName[i],
mCanRequestType[i], mShouldPlayImmediately[i],
mSeekPosition[i]);
mLoadRequested[i] = false;
}
}
}
答案 0 :(得分:1)
如果您浏览代码,您可以看到requestLoad方法除了equalation之外什么都不做:
public void requestLoad(int target, String movieName, int seekPosition,
boolean playImmediately)
{
mMovieName[target] = movieName;
mSeekPosition[target] = seekPosition;
mShouldPlayImmediately[target] = playImmediately;
mLoadRequested[target] = true;
}
您需要在渲染器类中加载视频:
mVideoPlayerHelper[i].load(mMovieName, mCanRequestType, mShouldPlayImmediately, mSeekPosition);
答案 1 :(得分:1)
我已尝试按照您上面列出的步骤操作,但出于某种原因,它仍然无法从SD卡加载视频。
总结一下,我已更新:
mMovieName[0] = Environment.getExternalStorageDirectory().getPath()+"/myVideoName.mp4";
使用下面列出的方法覆盖VideoPlayback.java中的QCARUpade
@覆盖 public void onQCARUpdate(State state){ if(loadNewVideo){ mMovieName [0] = Environment.getExternalStorageDirectory()。getPath()+“/ myVideoName.mp4”; mRenderer.requestLoad(0,mMovieName [0],0,false); }
你在哪里获得了loadNewVideo soroosh的价值?这是一个新变量吗?
在VideoPlayback.java中添加了changeVideo方法
private boolean changeVideo(){ boolean result = true;
mMovieName[STONES] = Environment.getExternalStorageDirectory().getPath()+"/myVideoName.mp4";
mRenderer.requestLoad(STONES, mMovieName[STONES], 0, false);
mRenderer.loadVideo(STONES);
return result;
}
4为VideoPlaybackRenderer.java添加了loadVideo方法:
public void loadVideo(int i)
{
if (mVideoPlayerHelper[i] != null)
{
mVideoPlayerHelper[i].unload();
if (!mVideoPlayerHelper[i]
.setupSurfaceTexture(videoPlaybackTextureID[i]))
mCanRequestType[i] = MEDIA_TYPE.FULLSCREEN;
else
mCanRequestType[i] = MEDIA_TYPE.ON_TEXTURE_FULLSCREEN;
if (mLoadRequested[i])
{
mVideoPlayerHelper[i].load(mMovieName[i],
mCanRequestType[i], mShouldPlayImmediately[i],
mSeekPosition[i]);
mLoadRequested[i] = false;
}
}
}
最后,我更新了VideoPlayerHelper.java中的加载方法:
mMediaPlayer.setDataSource(Environment.getExternalStorageDirectory()的getPath()+ “/ myVideoName.mp4”);