livecode.com
  • Home
  • Download
  • Developers
  • Academy
  • Community
  • Store
  • Support
  • About
LiveCode Lessons » How To - LiveCode Mobile Tasks » How do I play a video in part of the screen in iOS

Topics

  • Getting Started with Android 3
    • How do I Become an Android Developer on a PC?
    • How do I Become an Android Developer on a Mac?
    • The Basics: How do I Create Hello World on Android?
  • Getting Started with iOS 2
    • How do I Become an iOS Developer?
    • How do I use Core Location in revMobile
  • LiveCode Mobile Tasks 22
    • How do I Develop Cross-Platform in LiveCode?
    • How do I send an email from my mobile device?
    • How do I use multi-touch to move more than one object?
    • How do I use the Question and Password Dialogues in LiveCode Mobile?
    • How do I Capture Images in LiveCode Mobile?
    • How do I detect a shaking motion using LiveCode mobile?
    • LiveCode Mobile Video How-To's - Shake
    • How do I implement a multi-touch pinch motion?
    • LiveCode Mobile Video How-To's - Multi-touch
    • How do I play a video in part of the screen in iOS
    • Displaying Assets On Differing Screen Resolutions
    • How to create and use an SQLite database
    • How do I get an image from my mobile photo library
    • How do I implement in-app purchases in LiveCode?
    • Accessing Facebook Api's using LiveCode
    • Mobile Orientations
    • Using local notifications
    • Using custom URL schemes
    • Using multi-channel audio on mobile
    • How do I get the Location and use the Digital Compass?
    • How do I use Ads in LiveCode?
    • Creating a native scroller to scroll a field
  • iOS Tasks 19
    • How do I build an iPhone application for iOS?
    • How do I Configure the Status Bar in iOS?
    • How do I make a phone call on the iPhone?
    • How do I use Native Text Controls on iOS
    • How do I use the Browser Control?
    • How do I read/write to files in iOS?
    • How do I Send HTML E-Mails with Attachments in iOS?
    • Installing custom fonts on iOS
    • How do I use the Question and Password Dialogues in iOS?
    • How do I play sounds on an iOS device?
    • How do I use the Picker View on an iPhone?
    • How do I Access Maps on iOS?
    • Creating a simple stock control application for the iPad
    • How do I Create a Distribution Profile for iOS?
    • How do I Submit an iOS App to the App Store?
    • How do I set up an App for Submission to iTunes Connect?
    • How do I use the Date Picker View on an iPhone?
    • How do I use Push Notifications with iOS?
    • How do I Develop iOS Code for Standard and Retina Devices?
  • Android Tasks 4
    • Using the hardware "back" button on Android
    • How do I Create an Android App for Distribution?
    • How do I Create a Self-Signed Certificate for an Android App?
    • How do I use Push Notifications with Android?

Last Updated

Mar 24, 2011

Download Lesson PDF

Other Resources

  • Getting Started with LiveCode

  • Get Up and Running with LiveCode
  • Getting Started with LiveCode Development
  • LiveCode Concepts

  • Features, concepts and aspects of LiveCode
  • LiveCode Lessons

  • How To - Step-By-Step Guides To Tasks In LiveCode
  • How To - LiveCode Server Tasks
  • How To - LiveCode Mobile Tasks
  • How To - LiveCode Sample Scripts
  • How to - LiveCode Marketplace Products
  • How to Purchase and License LiveCode
  • Tutorials

  • Creating a Video Library Application
  • Data Grid

  • LiveCode Data Grid
  • Data Grid Tips & Tricks
  • Converting the Stock Program

Comments

14 for this lesson

  • Prev: LiveCode Mobile Video How-To's - Multi-touch
  • Next: Displaying Assets On Differing Screen Resolutions

How do I play a video in part of the screen in iOS

This lesson shows you how to create an iOS video controller and load a video.

Attached Files

  • iOSNativeVideoLesson.zip

Setup your stack and simulation settings

Zoom

-) Create a new stack
-) Resize it to 1024 x 768
-) File > Standalone application settings
1) Go to the iOS tab
2) For the purposes of this example set "Supported Devices" to 'iPad'. This tutorial applies equally to iPhone and iPods

Setup your video file

Zoom

For this test we need a video. We've exported a portion of the 4.6 promo video at a low quality which is contained in the sample zip attached to this lesson. We need to include it in our build:

1) In the standalone setting pane, go to 'Copy Files'
2) Click 'Add File..." to browse to our video file
3) It should appear in the list

We should now have a stack that is setup for simulation with our video file included. We can start coding.

Create our control in script

Open the card script and paste the following code. The green comments explain what we are doing.

on openCard
// Check the control doesn't already exist. If so delete and recreate it
if "ioscontrol" is among the lines of iphoneControls() then
controlDelete
end if
iphoneControlCreate "player", "ioscontrol"

// Set the basic properties including visibility, rectangle and video file path
iphoneControlSet "ioscontrol", "filename", specialFolderPath("engine") & "/video.mp4"
iphoneControlSet "ioscontrol", "preserveAspect", true
iphoneControlSet "ioscontrol", "showController", true
iphoneControlSet "ioscontrol", "visible", true
iphoneControlSet "ioscontrol", "rect", "250,200,783,500"

// Start playing the video
iphoneControlDo "ioscontrol", "play"
end openCard

on closeCard
// Delete the control when we leave the card
controlDelete
end closeCard

on controlDelete
// Delete the control
iphoneControlDelete "ioscontrol"
end controlDelete

Test in the simulator

Click on the simulate button to test.

  • Prev: LiveCode Mobile Video How-To's - Multi-touch
  • Next: Displaying Assets On Differing Screen Resolutions

Comments (14)

grovecat Saturday Sep 17 at 03:30 AM

When I fire up the stack from the zip file, I get the following error message:

Type Handler: can't find handler
Object card id 1002
Line iphoneControlCreate "player", "ioscontrol"
Hint iphoneControlCreate

As far as I can see, the script is identical to that shown on this page.

What is the problem?

Elanor Buchanan Monday Sep 19 at 06:15 AM

Hi

This causes a script error because iphoneControlCreate is only supported on iOS, not the desktop. The script should run correctly on an iOS simulator or device.

To prevent the error you can check the platform eg

if the platform is "iPhone" then
iphoneControlCreate "player", "ioscontrol"
end if

so the command is only called when running under iOS.

I hope that helps.

Elanor

michael Thursday Jun 21 at 04:57 AM

hi.

thank you for this tuts,

thought I need some help.

I want the player to be in full screen upon opening the card.

what code should I add?

thank you.

Hanson Schmidt-Cornelius Tuesday Jul 10 at 07:00 AM

Hi Michael,

have a look at the dictionary entry for "iphoneControlSet". Under the heading "Player Specific Properties" you will find all the properties that can be set or read.

You will want to set the property "fullscreen" to true.

Kind Regards,

Hanson

porter584 Monday Sep 03 at 12:19 PM

Is it possible to have more than one ios video player on the screen at one time, how would this be done,

Also, could you have an invisible 'play' button above the player that triggers the video, and then either remains active to replay the movie, or then disappear along with the player leaving the background?

Many thanks.

Hanson Schmidt-Cornelius Tuesday Sep 04 at 07:27 AM

Hi Porter584,

the answer is yes to both questions, but playback may be impaired, depending on the processing power of the device.

You can create a number of players using "iphoneControlCreate". Then control these players with the relevant "iphoneControlSet", "iphoneControlDo" ... commands.

You can make a button invisible by either giving it the pattern of the background or you can set it to opaque and remove all of the border types.

Kind Regards,

Hanson

Charlie Friday Oct 19 at 12:10 AM

Great tutorial, but a minor mistake in it caused me several hours of frustration. The lines:

if "ioscontrol" is among the lines of iphoneControls() then
controlDelete
end if

should be:

if "ioscontrol" is among the lines of iphoneControls() then
iphoneControlDelete "ioscontrol"
end if

I know it seems obvious, but as someone who is new to LiveCode and iOS development, I just assumed that the tutorial would be right, so I was looking everywhere in my program to find the problem except for the part I copied verbatim from the tutorial!

Anyway, no biggie, but it probably should be updated.

Hanson Schmidt-Cornelius Friday Oct 19 at 06:29 AM

Hi Charlie,

yes you are right, the command to delete a control is as you describe. The code in this lesson is implemented in a modular structure with wrapper command calls that can be expanded with additional functionality, if required.

There is a command "controlDelete" that wraps "iphoneControlDelete "ioscontrol"".

In this short code example it is probably not necessary to use this kind of wrapper functionality, but I would like to keep it. Our discussion may be valuable to other developers.

Kind Regards,

Hanson

Charliew Tuesday Oct 23 at 08:46 AM

Thanks, Hanson. I can see how that functionality would be useful. Where is the method for setting up such a structure described? I don't see it in this tutorial, but since I'm not familiar with the technique I don't know what I'm looking for.

Hanson Schmidt-Cornelius Tuesday Oct 23 at 12:23 PM

Hi Charliew,

sure, it is just a small snippet of code in the tutorial. Look for the following command and body:

on controlDelete
// Delete the control
iphoneControlDelete "ioscontrol"
end controlDelete

The "on controlDelete" and "end controlDelete" wrap around the code that is to be executed. In this case the body of this command executes "iphoneControlDelete "ioscontrol"". So when you call the command "controlDelete" you are executing the body of "controlDelete".

Basically what happens in this example is that calling "controlDelete" invokes "iphoneControlDelete "ioscontrol"". So calling "controlDelete" or "iphoneControlDelete "ioscontrol"" should fundamentally do more or less the same thing. The only requirement is that you have to add a bit more code that tells LiveCode what to do when you call "controlDelete".

Kind Regards,

Hanson

Ian Stewart Friday Mar 15 at 04:51 PM

Hello

I am running this code in Livecode 5.5.4 and with Simulator 6.0 which runs other things. It won't run on the simulator. I can see the app but when I click on it simply shows a livecode splash screen briefly and then I see the iPad home with the icon for the app once again. No video. Any ideas on what might be happening here>?

Regards
Ian

Hanson Schmidt-Cornelius Tuesday Mar 19 at 01:12 PM

Hi Ian,

there is a bug when playing videos on the simulator under iOS 6.0. This has been addressed in LiveCode 6.0.0.

Kind Regards,

Hanson

Alan Monday Apr 01 at 05:58 AM

Hello,

I am also running Livecode 5.5.4. and the simulator iOS 6.1
I purchased all the relevant add ons, only to find, that the one feature I need to test is faulty under 5.5.4.

When can I get LiveCode 6.0.0 for this to be addressed?

Hanson Schmidt-Cornelius Tuesday Apr 02 at 05:30 AM

Hi Alan,

if you are sure that the issue has been resolved in 6.0.0, then the gm version is due to be released very soon.

If you would like to find out if a particular issue you are having has been reported or is being addressed, then you can access our bug database at quality.runrev.com.

The status should indicate to you if a bug fix is available in the latest release of LiveCode. You can also review the release notes that come out with LiveCode, in order to determine if a particular bug has been included in a release.

Kind Regards,

Hanson

Add your comment

E-Mail me when someone replies to this comment
Brought to you by RunRev Ltd, Registered in Scotland, No. SC200728