Using script to display imported video by ID

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Location: USA
Contact:

Using script to display imported video by ID

Post by reelstuff » Sat Jan 05, 2008 4:02 pm

Hello, I was searching through the documentation and the forum here for a way to use a button script to play a Video file that I imported into a stack, I can see the video is there and it plays when I click it in the application browser,

One little side note, it loads over the application browser and cannot be closed unless you close the app browser, (interesting behaviour)

but I digress.

What I want to do is to play that video by ID using a button on a card.

Update, I found that I can play the imported video clip,

Code: Select all

on mouseUp
  play videoclip "myvideo.mov"
end mouseUp
However, there are no controls, is there a way to wrap the video in a player so there are controls, to pause play video?



Thanks in advance for any suggestions.

Lynn P.
Posts: 79
Joined: Sun Apr 09, 2006 1:09 pm

Post by Lynn P. » Sat Jan 05, 2008 7:21 pm

To my knowledge, you have to use a QT player object to hold the movie in order to access the controls or "badge" as it's called. The videoClip object has no such properties, it's simply an object that contains movie data. A player object offers much more control over playback.

You can either create it beforehand by dragging one from the Rev palette (or using the File menu) or do it by script.

If you place a player object on a card, you can tell it to play the movie file you imported to your stack via script:

Code: Select all

 set the fileName of player "myPlayer" to "/myVideo.mov" 
You can also type in "/myVideo.mov" into the player's inspector window.

Note the slash before the movie name which indicates the movie is contained in your stack. Read up on the player object in the docs for more info. :D

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Location: USA
Contact:

Post by reelstuff » Sat Jan 05, 2008 8:10 pm

thank you, I will try that out right away, I tried something like that but failed to put the / in front, that should cure it,

Tim

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Location: USA
Contact:

Post by reelstuff » Sat Jan 05, 2008 9:14 pm

thanks for the help, something must be off, tried several different methods of getting the video to play,

Used a script, to set file name, does not play,

tried entering /myvideo.mov into inspector, player framework show but video does not.

Not sure why this would be that difficult to manage, I am probably just missing something in the scripting.

I did check the documentation, which is version 1.0 a little behind the development of the tool,

I saw several methods but none would work with my version of rev which is 2.8.1

I am sure there must be a way to use video in a rev application without having to go through all these hoops,

thanks for the help, I will continue to look around to see if I can spot something that will do the trick.

Tim

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Sun Jan 06, 2008 1:01 am

the problem you have is most likely that there are two ways to use video in rev. the player object uses different commands then the player clip, and it's a bit hard to find them all. Here's a small sampling you can look up for details in the docu:

player object:
player
start
playStopped
currentTime
timeScale
stop
showBadge
showController


player clip:
play
movie

generally, the player object gives you more control, but needs a movie file in the disk.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Lynn P.
Posts: 79
Joined: Sun Apr 09, 2006 1:09 pm

Post by Lynn P. » Sun Jan 06, 2008 1:56 am

Hi Tim ~

I think I'm a bit confused about what exactly you want to do. :?
In your first post you said you wanted the controls available which is why you would set the fileName of a player object. This will load a movie into a player object, allowing the end user to start the movie using the controls. If you want the controls to just be there, but automatically start the movie without having the end user use the controls, put the following into your button script:

Code: Select all

on mouseUp
  set the fileName of player "myPlayer" to "/myvideo.mov"
  start player "myPlayer"
end mouseUp
You can also hide the controller from the user with "set the showBadge to false" if you want total control over the player object and not having the end user access to the movie controls. You can use all the other properties and commands of the player object to start, stop and pause the movie playing inside it.

From your last post... do you now want to play one movie, then play another one after it in the same player object?

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Location: USA
Contact:

Post by reelstuff » Sun Jan 06, 2008 1:22 pm

Lynn P. wrote:Hi Tim ~

I think I'm a bit confused about what exactly you want to do. :?
In your first post you said you wanted the controls available which is why you would set the fileName of a player object. This will load a movie into a player object, allowing the end user to start the movie using the controls. If you want the controls to just be there, but automatically start the movie without having the end user use the controls, put the following into your button script:

Code: Select all

on mouseUp
  set the fileName of player "myPlayer" to "/myvideo.mov"
  start player "myPlayer"
end mouseUp
You can also hide the controller from the user with "set the showBadge to false" if you want total control over the player object and not having the end user access to the movie controls. You can use all the other properties and commands of the player object to start, stop and pause the movie playing inside it.

From your last post... do you now want to play one movie, then play another one after it in the same player object?
Thank you for taking time to post,

I tried just about every possible combination to get the video to load then play, apparently there is a problem somewhere, I tested using the script you so very kindly provided and while the file name does change the video does not load to the card.

I thought I had a solution last night, but found that this did not work when build in a standalone.

I guess its back to the drawing board, thanks for your help I appreciate the effort.

In answer to your question, I have seven videos that I want to put into either stacks or into one stack, which ever way I can get it to work. then play the videos separately.

Tim

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Sun Jan 06, 2008 2:23 pm

Code of a button:

Code: Select all

on mouseUp
  answer folder "folder with movies" --and only movies!
  if it <> "" and the result = "" then --chosen folder path is in the var "it"
    set the defaultfolder to it
    put the files into temp
    filter temp without ".*" --to get rid of hidden files
    set the moviefiles of player 1 to temp --the moviefiles is a custom property
    set the filename of player 1 to line 1 of temp
    start player 1
  end if
end mouseUp

Code of player 1:

Code: Select all

on playstopped
  put the filename of me into lastMovie
  set the filename of me to ""
  put lineoffset(lastMovie, the moviefiles of me)+1 into nextLineNumber
  if nextLineNumber <= the number of lines of the moviefiles of me then
    set the filename of me to line nextLineNumber of the moviefiles of me
    start me
  else --end of list, stop playback
    set the paused of me to true
  end if
end playstopped
This code works perfectly for me, please look terms up in the docu if you don't know what they do. I used some advanced concepts like the defaultfolder and a custom property, they simplify the code, but are harder to grasp on first encounter, so don't give up easily.

Custom Properties:
they work similar to global variables, but are attached to objects, and thus get saved together with the rest of the stack, also you don't need to declare them.

The defaultFolder:
This works similar to the working directory in a terminal/consol. Rev will look for filenames in the defaultfolder, so if you just specify a filename but no path, that file needs to be within the defaultfolder (most of the time, there are exceptions).

The Files:
a list of all files within the defaultfolder (see also "the folders")

PlayStopped message:
Gets sent when a player stops by itself, or by the "play stop" command.

lineoffset function:
lineoffset let's you find a specific line in a list, i add one to get the next movie to play.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Location: USA
Contact:

Post by reelstuff » Sun Jan 06, 2008 2:37 pm

BvG wrote:Code of a button:

Code: Select all

on mouseUp
  answer folder "folder with movies" --and only movies!
  if it <> "" and the result = "" then --chosen folder path is in the var "it"
    set the defaultfolder to it
    put the files into temp
    filter temp without ".*" --to get rid of hidden files
    set the moviefiles of player 1 to temp --the moviefiles is a custom property
    set the filename of player 1 to line 1 of temp
    start player 1
  end if
end mouseUp

Code of player 1:

Code: Select all

on playstopped
  put the filename of me into lastMovie
  set the filename of me to ""
  put lineoffset(lastMovie, the moviefiles of me)+1 into nextLineNumber
  if nextLineNumber <= the number of lines of the moviefiles of me then
    set the filename of me to line nextLineNumber of the moviefiles of me
    start me
  else --end of list, stop playback
    set the paused of me to true
  end if
end playstopped
This code works perfectly for me, please look terms up in the docu if you don't know what they do. I used some advanced concepts like the defaultfolder and a custom property, they simplify the code, but are harder to grasp on first encounter, so don't give up easily.

Custom Properties:
they work similar to global variables, but are attached to objects, and thus get saved together with the rest of the stack, also you don't need to declare them.

The defaultFolder:
This works similar to the working directory in a terminal/consol. Rev will look for filenames in the defaultfolder, so if you just specify a filename but no path, that file needs to be within the defaultfolder (most of the time, there are exceptions).

The Files:
a list of all files within the defaultfolder (see also "the folders")

PlayStopped message:
Gets sent when a player stops by itself, or by the "play stop" command.

lineoffset function:
lineoffset let's you find a specific line in a list, i add one to get the next movie to play.
Thank you for posting you have given me a lot to think about, It looks like I need to dig a little deeper and examine the process in depth.

I can see from your examples that playing movies using the player object requires thought and some additional reading on my part, thank you for the examples, that explains a lot about what I was missing in trying to put this together,

I appreciate the help.
:)

kotikoti
Posts: 72
Joined: Tue Apr 15, 2008 7:35 pm

Post by kotikoti » Fri Aug 29, 2008 3:56 pm

Hi reelstuff et all,
Did you manage to get the videoclips (imported) to work in a QT object :- to be able to use the controllers...

I can see this topic has been checked a few times but no solution appears to be in place.

Does RR as a company look at this forum to see items needing clarification/assistance for their users.

Anyone with time to spare and has this sussed out, please share with us on how this is achieved.

As for my setup, I manage to import the video clips to the stack, can play the video files from the "application browser", and can run the clip using script as follows

Code: Select all

on mouseUp
  play videoclip "phys_demo1.mov"
end mouseUp
Using a video object, I can't succeed from code as follows to add the file to path...

Code: Select all

on mouseUp
  set the fileName of player "myPlayer" to "/phys_demo1.mov" 
end mouseUp
What I get when I do that is a blank player item. only sunken border showing...

Please assist...

Koti2

RR version 2.9, Windows Vista Home
Build 160
Version 2.9.0
Platform: Windows

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Location: USA
Contact:

Post by reelstuff » Fri Aug 29, 2008 5:14 pm

kotikoti wrote:Hi reelstuff et all,
Did you manage to get the videoclips (imported) to work in a QT object :- to be able to use the controllers...

I can see this topic has been checked a few times but no solution appears to be in place.

Does RR as a company look at this forum to see items needing clarification/assistance for their users.

Anyone with time to spare and has this sussed out, please share with us on how this is achieved.

As for my setup, I manage to import the video clips to the stack, can play the video files from the "application browser", and can run the clip using script as follows

Code: Select all

on mouseUp
  play videoclip "phys_demo1.mov"
end mouseUp
Using a video object, I can't succeed from code as follows to add the file to path...

Code: Select all

on mouseUp
  set the fileName of player "myPlayer" to "/phys_demo1.mov" 
end mouseUp
What I get when I do that is a blank player item. only sunken border showing...

Please assist...

Koti2

RR version 2.9, Windows Vista Home
Hi, thanks for posting, I never made any progress with this, instead I used another solution, there may be more options now than before, I hope to someday be able to use FLV video, however that appears to be in the future.

let us know how it goes,

SparkOut
Posts: 2862
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Sat Aug 30, 2008 3:21 am

A workaround (however dismal) is not to import the files as videoclips, but just as binfiles, and store them in a custom properties of the stack or card. This will make them portable with the standalone.
Then when you need to play the video clips, you can write them out to specialFolderPath("Temporary") and set the filename to that path/name to play.

kotikoti
Posts: 72
Joined: Tue Apr 15, 2008 7:35 pm

Post by kotikoti » Sat Sep 06, 2008 3:45 am

Thanks SparkOut, another approach, will give it a try... Haven't used custom properties as yet, will update on findings...
Build 160
Version 2.9.0
Platform: Windows

Post Reply

Return to “Talking LiveCode”