Adding video... how?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Adding video... how?

Post by ctflatt » Sun Mar 06, 2011 2:39 am

Maybe I've been at this too long today, but I am trying to add video playback to my mobile stack.

I feel like I'm missing something basic. Here's what I've done.

Placed a button on the first card in stack. Button handler:

Code: Select all

on mouseUp
   play specialFolderPath("engine") & "/media/creativity.mov"
end mouseUp
Standalone settings are set to include the video in a media folder, and this is verified by building the standalone and "Show Package Contents". The video is there.

The video will not play in simulator or on device.

Can someone detail what needs to be done, step-by-step, to achieve successful playback of video in iOS?

Many thanks!

:Todd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Adding video... how?

Post by bn » Sun Mar 06, 2011 10:29 am

Hi Todd,

you have to add the word video to your play command for iOS. As in

Code: Select all

play video specialFolderPath("engine") & "/media/creativity.mov"
this is the version without controller that is mentioned in the documentation. It sends the "movieTouched" message if you touch the movie, so you can stop it with

Code: Select all

on movieTouched 
   play stop
end movieTouched
in the card script.

I you want the controller to show you script:

Code: Select all

on mouseUp
   set the showController of the templateplayer to true
   play video (specialFolderPath("Engine") & "/media/creativity.mov")
end mouseUp
that way the user can control the movie via the controller

That took me a long time to figure out since the documentation is less than clear for me on that:
play ( video-file | video-url )
How is one supposed to guess the correct syntax from that?

Please note that the iOS devices dont play just any of the .mov files that work on the desktop. I successfully exported/converted via Quicktime Player using .m4v or .3gp, .3gp being very small but also low qualtiy. Other formats may work but I only tried these two.

Kind regards

Bernd


EDIT:

A WORD OF CAUTION:


if you are on a Mac and copy code from the forum to your scripts and you want these scripts to run on iOS then please watch out for a strange bug.

Currently the copy/paste from Forum to the script editor adds ASCII 202 insted of just spaces into the indention.This will not affect the performance in the IDE. BUT if you want to run the same script in the Simulator or a device it will fail silently, as if no code was entered. That bit me a couple of times.

The remedy is to either retype the text (cumbersome)
or to copy the script to TextWrangler (a free text editing program) and then -> Menu "Text" -> "Convert to ASCII" and copy the text into the script editor.
Additionally you have the option to show invisible characters in TextWrangler, which is at times very handy.

TextEdit -> convert to text will often not do.

Bernd

EDIT 2

RunRev is aware of the ASCII 202 problem and it is fixed for the 4.6 version of Livecode. (as of DP6)
Last edited by bn on Sun Mar 06, 2011 1:17 pm, edited 1 time in total.

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: Adding video... how?

Post by ctflatt » Sun Mar 06, 2011 11:53 am

Bernd:

That did it.

I thought I was going crazy.

I would have never figured out the right syntax from the documentation.

Thanks, again!

:Todd

dalkin
Posts: 183
Joined: Wed Jul 04, 2007 2:32 am
Contact:

Re: Adding video... how?

Post by dalkin » Wed Mar 09, 2011 6:38 am

I'm having a little trouble with the movieTouched aspect of this. So far, my stack consists of 1 card with a button that is coded as:

Code: Select all

on mouseup
   put URL "http://www.myurl.com.au/poems/poem3.txt" into field "Title"
   set the showController of the templatePlayer to true
   play video "http://www.myurl.com.au/poems/poem1.mov"
end mouseup

 on movieTouched
      play stop
      set the visible of card "1002" of stack "The Poet" to true
end movieTouched
Everything loads fine as you would expect but the problem is that when the movie plays, it loads and plays fine (with the controls showing) in an otherwise blank full-screen player and I can't see how to pass the movieTouched command. There aren't any scriptable controls in templatePlayer that I can see so I was hoping that passing the command from the button might "prime" it. Nothing happens when clicking the "Done" button and hitting the app controller quits the app when in fact I want it to go back to the screen (1002) with the button. But so far no luck.

Also, is there any way to load an image over the (otherwise) blank face of templatePlayer? The documentation seems a little light on this.
The underlying purpose of Al is to allow wealth to access skill
while removing from the skilled the ability to access wealth.

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: Adding video... how?

Post by ctflatt » Wed Mar 09, 2011 10:26 am

dalkin:

In my project, I have a video playing at startup that is not meant to be user-controllable, so I do not show controls. My stack setup is a blank first card, scripted for video as below, and a second card "main" with the app interface controls.

Code: Select all

on openCard
   play video (specialFolderPath("engine") & "/media/creativity_v.mov")
   wait 500 milliseconds
   visual effect dissolve
   go to card "main"
end openCard 
However, I read your post and thought I would try adding controls to see what you meant.

Now at startup the movie plays, but clicking the "Done" button does execute the rest of the script on the card. I do not have to implement a movieTouched script for this to work. It seems that the native player handles everything, and returns me to the correct card. I have only run this setup in the iOS simulator, but assume (love that word) it would perform the same way on the device.

If the native controller isn't working for you with a single card, could you implement a second card to control the playback of your video?

Add a card to your stack named "video". In this card place a script similar to the one above, leaving out the visual effect and 1/2 second delay if necessary:

Code: Select all

on openCard
   put URL "http://www.myurl.com.au/poems/poem3.txt" into field "Title"
   set the showController of the templatePlayer to true
   play video "http://www.myurl.com.au/poems/poem1.mov"
   go to card "main"
end openCard 
Name your first card "main", and change the button script to:

Code: Select all

on mouseUp
   go to card "video"
end mouseUp
Let me know if this works for you, or with your app's intended design.

HTH,

Todd

dalkin
Posts: 183
Joined: Wed Jul 04, 2007 2:32 am
Contact:

Re: Adding video... how?

Post by dalkin » Wed Mar 09, 2011 10:53 am

Hey Todd,

Many thanks for your interest. I tweaked it slightly but nothing is happening when I click the "Done" button. Is the "Done" button a target for a script?
The underlying purpose of Al is to allow wealth to access skill
while removing from the skilled the ability to access wealth.

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: Adding video... how?

Post by ctflatt » Wed Mar 09, 2011 11:05 am

Are you using 4.5.3?

I just checked the documentation again, and found this in italics in the last paragraph:

Note: The movieTouched message is not sent if the video is played with showController set to true.

dalkin
Posts: 183
Joined: Wed Jul 04, 2007 2:32 am
Contact:

Re: Adding video... how?

Post by dalkin » Wed Mar 09, 2011 11:14 am

Good spotting - I missed that.

The video is playing on a new card now with the following script attached to the card:

Code: Select all

on openCard
   set the showController of the templatePlayer to true
   play video "http://www.myurl.com.au/poems/poem1.mov"
   go to previous card
end openCard
and everything plays fine - the controller is visible but pressing the "Done" button should signal the player to continue the script but this isn't working in the Simulator
The underlying purpose of Al is to allow wealth to access skill
while removing from the skilled the ability to access wealth.

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: Adding video... how?

Post by ctflatt » Wed Mar 09, 2011 11:24 am

Can you attach your stack?

:Todd

Post Reply