Page 1 of 1

Play Video from Vimeo

Posted: Thu Jan 09, 2020 1:04 pm
by Bosstone
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

Re: Play Video from Vimeo

Posted: Thu Jan 09, 2020 1:43 pm
by Klaus
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

Re: Play Video from Vimeo

Posted: Fri Jan 10, 2020 5:17 am
by dunbarx
Please post here as well if you also post to the German forum. Sounds interesting

Craig

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 9:04 am
by Bosstone
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

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 1:57 pm
by Klaus
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

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 6:04 pm
by Bosstone
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

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 6:17 pm
by Klaus
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

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 6:49 pm
by Bosstone
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

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 7:10 pm
by Klaus
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
...

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 9:42 pm
by Bosstone
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!

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 9:55 pm
by Klaus

Code: Select all

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

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 10:04 pm
by Bosstone
Oh, I am soo stupid...

All the best,

Stefan

PS: Next step: Data Grid!

Re: Play Video from Vimeo

Posted: Sun Jan 12, 2020 10:11 pm
by bogs
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.