Log in or register to post comments

How to work for video from url in videoplayback

February 12, 2013 - 2:10am #1

Hello all,

I am working with Videoplayback sample of vuforia.I am using dat and xml for 3 images, and i also got image name while the camera is detecting any image of three imges. Now i want tIo play three different videos for those three images.I have started new activty for below android 4.0 devices and played video accordingly to image.

But my question is I am not able to play video from url for android above 4.0 devices which support video on texture.I need to play three different video for those three image after detection.

How to work for video from url in videoplayback

October 27, 2016 - 7:22am #19

AlessandroB wrote:

Hi,

you should be able to achieve your result by following these steps (as I just tested them):

 

VideoPlayback.java: 

Change the number of targets from 2 to your desired number of videos (e.g. 3):

public static final int NUM_TARGETS = 2; // change to 3

 

Then replace these two lines:

public static final int STONES = 0;
public static final int CHIPS = 1;

with these lines:

public static final int MY_FIRST_TARGET = 0;
public static final int MY_SECOND_TARGET = 1;
public static final int MY_THIRD_TARGET = 2;

 

Replace these two lines:

mMovieName[STONES] = "VuforiaSizzleReel_1.m4v";
mMovieName[CHIPS] = "VuforiaSizzleReel_2.m4v";

with these lines:

mMovieName[MY_FIRST_TARGET] = "myURK/videos/video1.m4v";
mMovieName[MY_SECOND_TARGET] = "myURK/videos/video2.m4v";
mMovieName[MY_THIRD_TARGET] = "myURK/videos/video3.m4v";

 

VideoPlaybackHelper.java:

Go to the load() method and replace this code:

AssetFileDescriptor afd = mParentActivity.getAssets().openFd(filename);
mMediaPlayer.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),
                           afd.getLength());                          
afd.close();

with this code snippet(assuming that the filename is now representing a video URL):

mMediaPlayer.setDataSource(filename);

 

Also, remove completely the following code snippet:

try
{
  // We need to verify that the file exists
   AssetFileDescriptor afd = mParentActivity.getAssets().openFd(filename);
   afd.close();
 }
  catch (Exception e)
 {
       DebugLog.LOGD("File does not exist");
        mCurrentState = MEDIA_STATE.ERROR;
        mMediaPlayerLock.unlock();
        mSurfaceTextureLock.unlock();
        return false;
  }

 

VideoPlayback.cpp:

Replace this code:

static const int NUM_TARGETS = 2;
static const int STONES = 0;
static const int CHIPS = 1;

with this:

static const int NUM_TARGETS = 3; // must match value defined in VideoPlayback.java
static const int MY_FIRST_TARGET = 0;
static const int MY_SECOND_TARGET = 1;
static const int MY_THIRD_TARGET = 2;

Also make sure to update all occurrences of CHIPS and STONES constants with the MY_FIRST_TARGET, MY_SECOND_TARGET, etc.

I hope this helps.

 

 

 

 

I tried this but it didn't work for me. I already verified the video link works fine (is not a youtube video), and I followed all of this instructions. Also, I verified that I manage the internet permission. I'm using android v5.1. What is happening is that the target is recognized and the play video image is showed but when I touch it to play video, it does nothing. Any idea?

How to work for video from url in videoplayback

December 21, 2014 - 10:36pm #18

Hi,

 I want to load more than three videos from the URL like maybe 6 or 10. Can anyone let me know how to do it ? Someone also mentioned about dynamically uploading them directly ,I;d be grateful if anyone gives out the details.Thanks in advance :) 

How to work for video from url in videoplayback

July 10, 2014 - 4:40am #17

Hi Laxmikantyadav1988,

                      I saw your posts here . Have you solved your issues if so please temme the steps to give different url for three different images.

Thanks in advance.

How to work for video from url in videoplayback

February 19, 2013 - 5:50am #16

Hi udayar,

the problem is that  you are trying to play a vdeo from a Youtube URL; unfortunately such URL does not point to an actual video file, so it cannot work;

to play a video from URL you need to point to an actual file, for instance this would be a "valid" URL:

http://com.my.org/videos/some_video_file.m4v

note that thu Youtube URL issue has been already discussed in other Forum threads as well (if you search the Forum, you can find some of them).

 

How to work for video from url in videoplayback

February 19, 2013 - 2:54am #15

Hi ,

I Followed all the steps what you mentioned but it throwing error in logcat (i.e)

02-19 16:21:08.420: E/QCAR(9639): Error while creating the MediaPlayer: java.io.FileNotFoundException: http://www.youtube.com/watch?v=B_f_i6h2AgE
02-19 16:21:08.420: E/MediaPlayer(9639): error (-38, 0)
02-19 16:21:08.420: E/MediaPlayer(9639): stop called in state 0
02-19 16:21:08.420: V/SurfaceView(9639): android.widget.VideoView@40b78388 got app visibiltiy is changed: false
02-19 16:21:08.475: W/MediaPlayer(9639): mediaplayer went away with unhandled events
 
this is the error coming for me .
could any one can say why it is.
 
 

 

How to work for video from url in videoplayback

February 14, 2013 - 2:00pm #14

Hi, what I meant in my previous message is simply  that in the VideoPlayback sample the videos are loaded at application startup and are just associated to CHIPS and STONES;

I cannot however guide you step-by-step in how to write your application; the Videoplayback sample already provides you with ALL the building blocks and all the necessary details to realize your Application; what I encourage you to do is to spend some time reading the sample and understanding the code with a bit of patience;

you can also check all the code snippets and guidelines that I already provided in this thread (see all previous posts).

 

 

How to work for video from url in videoplayback

February 14, 2013 - 9:22am #13

Hi, @ AlessandroB ,

one other thing i want to clear for myself that which things should i change inside cpp file as you suggested me some codes and logic in previous post.?

How to work for video from url in videoplayback

February 14, 2013 - 5:45am #12

 @ udayasam:

if the video is not playing it could be for two reasons:

  1. the URL is not valid (for instance, have you included the "http://" ? , in general check that the URL is correctly spelled)
  2. the video pointed to by the URL is not playable for some reasons (we saw reports that certain videos have problems being streamed); in this case a good test is to try with different videos with different formats (for instance mp4 vs m4v, etc.)

I hope this helps.

How to work for video from url in videoplayback

February 14, 2013 - 5:41am #11

Laxmikantyadav1988:

you can also set the number of videos (and their URLs as well) dynamically; however that will require a bit of reworking of the code (with respect to the sample);

I cannot assist in writing the whole logic to do that (as this requires quite some coding and the details are up to your coding preferences), but if you search the Forum you might find some threads on this topic (other users already managed to implement dynamic loading/unloading of videos).

 

 

How to work for video from url in videoplayback

February 14, 2013 - 4:25am #10

Hi,

Actually the texture is displayed and play button also enabled once i clicked play button its goes some where and again its coming back to texure with play button. plz tell where i went wrong.

 

How to work for video from url in videoplayback

February 14, 2013 - 3:47am #9

Hi.Thanks For your response

can we make NUM_TARGET value in videoplayback.cpp (which is right now 3)  variable, like we are getting NUM_TARGET value from weburl.

How to work for video from url in videoplayback

February 14, 2013 - 2:22am #8

Hi,

you should be able to achieve your result by following these steps (as I just tested them):

 

VideoPlayback.java: 

Change the number of targets from 2 to your desired number of videos (e.g. 3):

public static final int NUM_TARGETS = 2; // change to 3

 

Then replace these two lines:

public static final int STONES = 0;
public static final int CHIPS = 1;

with these lines:

public static final int MY_FIRST_TARGET = 0;
public static final int MY_SECOND_TARGET = 1;
public static final int MY_THIRD_TARGET = 2;

 

Replace these two lines:

mMovieName[STONES] = "VuforiaSizzleReel_1.m4v";
mMovieName[CHIPS] = "VuforiaSizzleReel_2.m4v";

with these lines:

mMovieName[MY_FIRST_TARGET] = "myURK/videos/video1.m4v";
mMovieName[MY_SECOND_TARGET] = "myURK/videos/video2.m4v";
mMovieName[MY_THIRD_TARGET] = "myURK/videos/video3.m4v";

 

VideoPlaybackHelper.java:

Go to the load() method and replace this code:

AssetFileDescriptor afd = mParentActivity.getAssets().openFd(filename);
mMediaPlayer.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),
                           afd.getLength());                          
afd.close();

with this code snippet(assuming that the filename is now representing a video URL):

mMediaPlayer.setDataSource(filename);

 

Also, remove completely the following code snippet:

try
{
  // We need to verify that the file exists
   AssetFileDescriptor afd = mParentActivity.getAssets().openFd(filename);
   afd.close();
 }
  catch (Exception e)
 {
       DebugLog.LOGD("File does not exist");
        mCurrentState = MEDIA_STATE.ERROR;
        mMediaPlayerLock.unlock();
        mSurfaceTextureLock.unlock();
        return false;
  }

 

VideoPlayback.cpp:

Replace this code:

static const int NUM_TARGETS = 2;
static const int STONES = 0;
static const int CHIPS = 1;

with this:

static const int NUM_TARGETS = 3; // must match value defined in VideoPlayback.java
static const int MY_FIRST_TARGET = 0;
static const int MY_SECOND_TARGET = 1;
static const int MY_THIRD_TARGET = 2;

Also make sure to update all occurrences of CHIPS and STONES constants with the MY_FIRST_TARGET, MY_SECOND_TARGET, etc.

I hope this helps.

 

 

 

How to work for video from url in videoplayback

February 14, 2013 - 12:06am #7

Hi,

I have given the case to play video to play video on texture in videoplaybackrender.java inside onSurfaceCreated method like this.

stones chips and dust are images name. and myurl is weburl for video.and detected image is a string which contains current detecting image name.i m putting below case inside onsurfaecreated method. i

                    if(detectedimage==stones)
{
                    mVideoPlayerHelper[i].load("myurl/video/a.mp4", mCanRequestType[i], mShouldPlayImmediately[i], mSeekPosition[i]);
}
 
                   if(detectedimage==chips)
{
                    mVideoPlayerHelper[i].load("myurl/video/b.mp4", mCanRequestType[i], mShouldPlayImmediately[i], mSeekPosition[i]);
}
 
                    if(detectedimage==dust)
{
                    mVideoPlayerHelper[i].load("myurl/video/c.mp4", mCanRequestType[i], mShouldPlayImmediately[i], mSeekPosition[i]);
}
 
      

     

                Am i mistaking somewhere, i want to play three different video on texture

 

How to work for video from url in videoplayback

February 12, 2013 - 6:07am #6

Yes, you can put the URLs in the mMovieName array.

 

How to work for video from url in videoplayback

February 12, 2013 - 6:00am #5

Hi,,

it means i have to give all three urls in mMovieName array..? and based on serial it will take url to play video. am i right... or is there any other way.?

How to work for video from url in videoplayback

February 12, 2013 - 5:31am #4

Hi, in VideoPlaybackHelper, the code where you set the URL is in the load() method; this method is called from the VideoPlaybackRenderer class for each of the videos in your list, as shown in this snippet taken from VideoPlaybackRenderer:

for (int i = 0; i < VideoPlayback.NUM_TARGETS; i++)
        {

            if (mVideoPlayerHelper[i] != null)
            {
                // The VideoPlayerHelper needs to setup a surface texture given the texture id created in native
                // Here we inform the video player that we would like to play the movie
                // both on texture and on full screen
                // Notice that this does not mean that the platform will be able to do what we request
                // After the file has been loaded one must always check with isPlayableOnTexture() whether
                // this can be played embedded in the AR scene
                if (!mVideoPlayerHelper[i].setupSurfaceTexture(getVideoTextureID(i)))
                    mCanRequestType[i] = MEDIA_TYPE.FULLSCREEN;
                else
                    mCanRequestType[i] = MEDIA_TYPE.ON_TEXTURE_FULLSCREEN;

                // And now check if a load has been requested with the parameters passed from the main activity
                if (mLoadRequested[i])
                {
                    mVideoPlayerHelper[i].load(mMovieName[i], mCanRequestType[i], mShouldPlayImmediately[i], mSeekPosition[i]);
                    mLoadRequested[i] = false;
                }
            }
        }

As you can see, for each video you call mVideoPlayerHelper[i].load(mMovieName[i], .... ) 

This means that, for example, if you pass a URL for each video (in place of mMovieName[i]), you can get a different URL for each video (then, of course, you will need to adjust the load() method to use the URL parameter instead of the "filename" parameter.

You can also implement things a bit differently, but that's up to you and specific to your application logic; the VideoPlayback sample contains all the building blocks to allow you to achieve your aim easily.

 

How to work for video from url in videoplayback

February 12, 2013 - 3:23am #3

Hi,

But in videoplaybackHelper.java you can set only one data source(fix data source).Can i give some condition for three images and to play video accordigly.

How to work for video from url in videoplayback

February 12, 2013 - 3:01am #2

Hi, you can play video from URL both in fullscreen mode (Android 2.x and 3.x) and in video-on-texture mode as well (on Android 4.0 and above);

the VideoPlayerHelper.java file contains some code that you need to change to point the media player to your URL;

this is explained in this Thread as well:

https://developer.vuforia.com/forum/issues-and-bugs/it-possible-stream-video-url-video-playback-example

 

Log in or register to post comments