Reputation: 1191
I'm using vuforia SDK on android and I'm working with videoplayback sample code. I want to change the source file of the video at runtime. To do that, when I want to load a new video file, first I change the video file name like this:
mMovieName[0] = Environment.getExternalStorageDirectory().getPath()+"/video1.mp4";
I checked the path to the video file by loading it from the begining and it's correct. I put this line in this method:
onQCARUpdate(State state)
which is run in equal time steps. Then I load the new video like this in the same method:
mRenderer.requestLoad(0, mMovieName[0], 0, false);
SO in the end it looks like this:
@Override
public void onQCARUpdate(State state)
{
if(loadNewVideo)
{
mMovieName[0] = Environment.getExternalStorageDirectory().getPath()+"/video1.mp4";
mRenderer.requestLoad(0, mMovieName[0], 0, false);
}
}
But the problem is that nothing changes. The initial video continues as it was being played and no errors or crashes. Should I do something aside from these too or is it that I'm completely off?
EDIT:
I was not actually loading the video. I'm calling load method of videoHelper now but still the video doesn't change. It just freezes and I can hear its sounds.
In VideoPlayback.java I added this method which I'm calling inside onQCarUpdate once a single tap happens:
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;
}
Also added this method to VideoPlaybackRenderer.java (I just copied these from 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;
}
}
}
The address to the video is fine. I tried loading it as the first video and it plays fine. Both videos are on SD storage and I've modified VideoHelper.java to load from SD. I also checked and it does go into loadVideo once I tap outside the target.
EDIT:
I had to unload before loading a new video so what worked was this:
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;
}
}
}
Upvotes: 0
Views: 1358
Reputation: 63
hey unfortunately i dont have 50 reps to comment on any of the previous answers. thanks for sharing your answer soroosh and shayan.
i have tried following the steps you have listed above, but for some reason, it's still not able to load the video from the sd card.
to summarise, i have updated:
mMovieName[0] = Environment.getExternalStorageDirectory().getPath()+"/myVideoName.mp4";
overridden onQCARUpade in VideoPlayback.java with the method listed below
@Override public void onQCARUpdate(State state) { if(loadNewVideo) { mMovieName[0] = Environment.getExternalStorageDirectory().getPath()+"/myVideoName.mp4"; mRenderer.requestLoad(0, mMovieName[0], 0, false); } }
Where did you get the value for loadNewVideo soroosh? Is this a new variable?
added changeVideo method in VideoPlayback.java
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 added loadVideo method to VideoPlaybackRenderer.java:
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;
}
}
}
lastly, I updated load method in VideoPlayerHelper.java:
mMediaPlayer.setDataSource(Environment.getExternalStorageDirectory().getPath()+"/myVideoName.mp4");
Upvotes: 1
Reputation: 2042
if you explore the code, you can see the requestLoad method does nothing but equalation:
public void requestLoad(int target, String movieName, int seekPosition,
boolean playImmediately)
{
mMovieName[target] = movieName;
mSeekPosition[target] = seekPosition;
mShouldPlayImmediately[target] = playImmediately;
mLoadRequested[target] = true;
}
You need to load the video in the Renderer Class:
mVideoPlayerHelper[i].load(mMovieName, mCanRequestType, mShouldPlayImmediately, mSeekPosition);
Upvotes: 1