Play Video from Vimeo

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Bosstone
Posts: 9
Joined: Wed Jan 08, 2020 9:55 pm

Play Video from Vimeo

Post by Bosstone » Thu Jan 09, 2020 1:04 pm

Hi,

I am new to LiveCode - My Background is PHP and MySQL. I want to show Videos from Vimeo in my
app. The URL comes from a MySQL DB which I want to fetch via XML:

<vimeo>linktovimeo/video/372847164</vimeo>

I have seen, that I should use Web Browser for that action, but I have nothing seen in the documentation how to
use Data from XML for this action?

Thank you very much for your advice and help,

All the Best,

Stefan

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Play Video from Vimeo

Post by Klaus » Thu Jan 09, 2020 1:43 pm

Hi Stefan,

welcome to the forum!

Are you german? Stefan sounds like this, if yes, there is also a german LC forum:
http://www.livecode-blog.de/forums/foru ... ode-forum/

OK, what part do you need help with?
Extracting the VIMEO part form the XML or setting up the browser widget?


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Play Video from Vimeo

Post by dunbarx » Fri Jan 10, 2020 5:17 am

Please post here as well if you also post to the German forum. Sounds interesting

Craig

Bosstone
Posts: 9
Joined: Wed Jan 08, 2020 9:55 pm

Re: Play Video from Vimeo

Post by Bosstone » Sun Jan 12, 2020 9:04 am

Hi Klaus

thank you for your feedbck. I am Austrian, so the German Forum might also work :-) I have seen the tutorial

/m/4071/l/7011-how-to-read-in-data-from-an-xml-file

but there the XML File will be load from Desktop, how can I read from Web XML?

This is my XML File:

Code: Select all

<messen>
<messe>
<id>1</id>
<messe_1>Badener Hochzeitstage 2020</messe_1>
<vimeo>/video/372844380</vimeo>
</messe>
<messe>
<id>3</id>
<messe_1>Kärntner Hochzeitstage 2021</messe_1>
<vimeo>/video/364883457</vimeo>
</messe>
</messen>
So in my case, I have to do something like this:

Code: Select all

function readxml pFilePath
    local tXMLTreeID
    local tRoot
    local tResponse
    local tChildNode
    local tID
    local aRecords
    
    put revCreateXMLTreeFromFile(pFilePath, false, true, false) into tXMLTreeID
    put revXMLRootNode(tXMLTreeID) into tRoot -- "messen"
    put revXMLFirstChild(tXMLTreeID,tRoot) into tResponse -- "messe"
    repeat while "xmlerr" is not in tResponse
        put revXMLNodeContents(tXMLTreeID, tResponse & "/id") into tID
        put revXMLNodeContents(tXMLTreeID, tResponse & "/messe_1") into aRecords[tID]["messe_1"]
        put revXMLNodeContents(tXMLTreeID, tResponse & "/vimeo") into aRecords[tID]["vimeo"]
        put revXMLNextSibling(tXMLTreeID,tResponse) into tResponse
        if tResponse is empty then
            exit repeat
        end if
    end repeat
    return aRecords
end readxml
How can I get the Variable "aRecords[tID]["vimeo"] into the Web Browser?

Thank you very much,

Stefan

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Play Video from Vimeo

Post by Klaus » Sun Jan 12, 2020 1:57 pm

Hi Stefan,
but there the XML File will be load from Desktop, how can I read from Web XML?
just put it into a variable:

Code: Select all

...
put url("http://path_to/server.com/xml_file_here.xml") into tXML
## Now parse that variable with:
## put revCreateXMLTreeFromFile(pFilePath, false, true, false) into tXMLTreeID
put revXMLCreateTree(tXML, false, true, false) into tXMLTreeID
...
How can I get the Variable "aRecords[tID]["vimeo"] into the Web Browser?
Use the link in the XML tag like:

Code: Select all

...
put aRecords[tID]["vimeo"] into tVideoURL
set the url of widget "Your browser widget here..." to tVideoURL
## Done!
...
:-)


Best

Klaus

Bosstone
Posts: 9
Joined: Wed Jan 08, 2020 9:55 pm

Re: Play Video from Vimeo

Post by Bosstone » Sun Jan 12, 2020 6:04 pm

Hi Klaus,

thank you very much for your help and your advices. This Code is working when I connect it to a button, but how can I process it, when the
stack is loading?

Code: Select all

on mouseUp
   loadPreferences
end mouseUp



command loadPreferences
   put readPreferencesToXMLTree() into tTree
   
   if tTree is empty then
      exit loadPreferences
   end if
   
   processPreferencesTree tTree 
   
   revXMLDeleteTree tTree
end loadPreferences

private function readPreferencesToXMLTree
   
   put url("URL") into tXML
   put revXMLCreateTree(tXML, false, true, false) into tXMLTreeID
   put revXMLRootNode(tXMLTreeID) into tRoot -- "messen"
   put revXMLFirstChild(tXMLTreeID,tRoot) into tResponse -- "messe"
   repeat while "xmlerr" is not in tResponse
      put revXMLNodeContents(tXMLTreeID, tResponse & "/id") into tID
      put revXMLNodeContents(tXMLTreeID, tResponse & "/messe_1") into aRecords[tID]["messe_1"]
      put revXMLNodeContents(tXMLTreeID, tResponse & "/vimeo") into aRecords[tID]["vimeo"]
      put revXMLNextSibling(tXMLTreeID,tResponse) into tResponse
      if tResponse is empty then
         exit repeat
      end if
   end repeat
   put aRecords[tID]["vimeo"] into tVideoURL
   set the url of widget "Browser" to tVideoURL
   
end readPreferencesToXMLTree

private function processPreferencesTree tTree 
   put aRecords[tID]["vimeo"] into tVideoURL
   set the url of widget "Browser" to tVideoURL
end processPreferencesTree

Thank you very much for your feedback,

Stefan

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Play Video from Vimeo

Post by Klaus » Sun Jan 12, 2020 6:17 pm

Hi Stefan,

put your handlers and functions into the stackscript and then add this:

Code: Select all

on openstack
   ## Your other openstackstuff here...
   ## ... and here...

  ## Give the engine time to load all libraries etc:
  send "loadPreferences" to this stack in 10 
  ## = 10 ticks = 1/6 second 
  ## 1 second = 60 ticks
end openstack
Best

Klaus

Bosstone
Posts: 9
Joined: Wed Jan 08, 2020 9:55 pm

Re: Play Video from Vimeo

Post by Bosstone » Sun Jan 12, 2020 6:49 pm

Hi Klaus,

thank you very much for your help. It works like a charm :-)

When I try to work with random numbers, I try to work with

Code: Select all

put random(1) + 4 into rNumber
   
   put url("URL?messe=rNumber") into tXML
But I do not get any result. I think it is because I have to mask the variable. What is the syntax in LiveCode?

All the best,

Stefan

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Play Video from Vimeo

Post by Klaus » Sun Jan 12, 2020 7:10 pm

You are passing the STRING rNumber and not its content!

Code: Select all

...
put random(1) + 4 into rNumber
put url("URL?messe=" & rNumber) into tXML
...

Bosstone
Posts: 9
Joined: Wed Jan 08, 2020 9:55 pm

Re: Play Video from Vimeo

Post by Bosstone » Sun Jan 12, 2020 9:42 pm

Hi Klaus,

thank you very much. When I return the variable "rNumber", then it will be shown correct, but when I use
it with the URL then it is always "empty". I am using a field, there I see the error:

Code: Select all

put random(3) + 1 into rNumber
return rNumber
I just have 5 entries in this table of the db.
xmlerr, can't find element

Code: Select all

on openstack
   send "loadPreferences" to this stack in 10
end openstack

command loadPreferences
   put readPreferencesToXMLTree() into tTree
   if tTree is empty then
      exit loadPreferences
   end if 
   
end loadPreferences

private function readPreferencesToXMLTree
   
   put random(3) + 1 into rNumber
   
   put url("URLTO?messe= & rNumber") into tXML
   put revXMLCreateTree(tXML, false, true, false) into tXMLTreeID
   put revXMLRootNode(tXMLTreeID) into tRoot -- "messen"
   put revXMLFirstChild(tXMLTreeID,tRoot) into tResponse -- "messe"
   repeat while "xmlerr" is not in tResponse
      put revXMLNodeContents(tXMLTreeID, tResponse & "/id") into tID
      put revXMLNodeContents(tXMLTreeID, tResponse & "/messe_1") into aRecords[tID]["messe_1"]
      put revXMLNodeContents(tXMLTreeID, tResponse & "/vimeo") into aRecords[tID]["vimeo"]
      put revXMLNextSibling(tXMLTreeID,tResponse) into tResponse
      if tResponse is empty then
         exit repeat
      end if
   end repeat
   put aRecords[tID]["vimeo"] into tVideoURL
   set the url of widget "Browser" to tVideoURL
   put aRecords[tID]["messe_1"] into field "Field"
   
end readPreferencesToXMLTree

Thanks again for your help and advices!

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Play Video from Vimeo

Post by Klaus » Sun Jan 12, 2020 9:55 pm

Code: Select all

...
put url("URLTO?messe=" & rNumber) into tXML
...
Just as I wrote! 8)

Bosstone
Posts: 9
Joined: Wed Jan 08, 2020 9:55 pm

Re: Play Video from Vimeo

Post by Bosstone » Sun Jan 12, 2020 10:04 pm

Oh, I am soo stupid...

All the best,

Stefan

PS: Next step: Data Grid!

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Play Video from Vimeo

Post by bogs » Sun Jan 12, 2020 10:11 pm

Bosstone wrote:
Sun Jan 12, 2020 10:04 pm
Oh, I am soo stupid...
Well, so far you are merely unobservant, not stupid. If your next step is the big DG, you will need to practice being hyper meticulous.
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”