Loading Video from URL

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

digifilm
Posts: 12
Joined: Sat Mar 12, 2011 5:44 pm
Contact:

Loading Video from URL

Post by digifilm » Mon Aug 29, 2011 12:06 am

Hi,

I am trying to load a video from the web and then store it on iOS device and then play it.

I am having trouble with this code:

The file is not getting saved in "cache" folder.
It's not playing in the simulator either.
The mov is getting displayed as raw code in msg box however.
There is an error towards the end of the code too.

Code: Select all

on mouseUp

   put specialFolderPath("cache") & "/check.mov" into tMypath
   
   if there is a file tMyPath then
      
      iphoneControlSet "ioscontrol", "filename", tMyPath
      iphoneControlSet "ioscontrol", "preserveAspect", true
      iphoneControlSet "ioscontrol", "showController", true
      iphoneControlSet "ioscontrol", "visible", true
      iphoneControlSet "ioscontrol", "rect", "184,193,584,720"
      iphoneControlDo "ioscontrol", "play"

   else

      answer "Download Movie"
      put "binfile:" before tMyPath
      put URL "http://dirtysalsa.com/1/check.mov" into URL tMyPath

   end if

end mouseUp


Thanks,
Debdoot
Attachments
test-remote-video.livecode.zip
(2.14 KiB) Downloaded 291 times

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Loading Video from URL

Post by Jellicle » Mon Aug 29, 2011 5:12 am

You can't save files to the "engine", which is the app bundle itself:

"In general you should only create files within the documents, cache, and temporary folders. Indeed, be careful not to change or add any files within the application bundle. The application bundle is digitally signed when it is built, and any changes to it after this point will invalidate the signature and prevent it from launching."

I downloaded your movie to the Documents folder on iOS with this:

libUrlDownloadToFile "http://dirtysalsa.com/1/check.mov", specialfolderpath ("Documents") & "/check.mov"

Search the release notes to learn about the libUrlDownloadToFile command - it's useful if you need to track download progress as you go.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

digifilm
Posts: 12
Joined: Sat Mar 12, 2011 5:44 pm
Contact:

Re: Loading Video from URL

Post by digifilm » Mon Aug 29, 2011 6:18 am

Thanks Gerry. It worked. I had also skipped out on iphoneControlCreate.

Would you also be familiar with the pros and cons of storing in the Library folder.

Thanks for pointing out the callback for a progress bar.

Regards,
Debdoot

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Loading Video from URL

Post by Jellicle » Mon Aug 29, 2011 8:03 am

Debdoot, I quoted the iOS release notes in my previous reply - they are best source of info about this. Check out the File and folder handling section in particular.

I don't think it really matters whether your app writes downloaded files to the library or the documents folders; both are preserved between launches and backed up to iTunes when the device is synced, while the temporary and cache directories are not.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Loading Video from URL

Post by FourthWorld » Mon Aug 29, 2011 6:24 pm

Debdoot! I don't know how I missed your earlier posts, but very good to see you here! It's like old times. :)

Welcome aboard.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

digifilm
Posts: 12
Joined: Sat Mar 12, 2011 5:44 pm
Contact:

Re: Loading Video from URL

Post by digifilm » Mon Aug 29, 2011 9:28 pm

Hi Richard. So good to see you too. It is very nostalgic. Happy to be back. :D

digifilm
Posts: 12
Joined: Sat Mar 12, 2011 5:44 pm
Contact:

Re: Loading Video from URL - Progress Bar

Post by digifilm » Tue Aug 30, 2011 3:40 am

I adapted this code I found in a project. This code is working on the Mac fine but the progress bar is not working on the iOS simulator.

on mouseUp
put specialfolderpath("Library") & "/check2.mov" into tPathToLocalFile
libURLSetStatusCallback "showProgress", the long name of me
libUrlDownloadToFile "http://dirtysalsa.com/1/check2.mov", tPathToLocalFile, "downloadComplete"
end mouseUp

on downloadComplete
hide scrollbar "progressbar"
answer "Download done"
end downloadComplete

on showProgress pURL, pStatus
if the number of items in pStatus = 3 then
if the visible of scrollbar "ProgressBar" = false then
put the last item of pStatus into tTotalBytes
set the startValue of scrollbar "ProgressBar" to 0
set the endValue of scrollbar "ProgressBar" to tTotalBytes
show scrollbar "ProgressBar"
end if
set the thumbPosition of scrollbar "ProgressBar" to item 2 of pStatus
end if
end showProgress


Thanks.
Debdoot

digifilm
Posts: 12
Joined: Sat Mar 12, 2011 5:44 pm
Contact:

Re: Loading Video from URL

Post by digifilm » Tue Aug 30, 2011 3:55 am

Darn. Just figured out. iOS does not support libURL.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Loading Video from URL

Post by Jellicle » Tue Aug 30, 2011 3:56 am

I've never used the LC scrollbar so I can't comment on that. Instead, I use the following in my urlProgress script:

on urlProgress url,downloadmessage,recvd,bytesTotal

-- lots of other code snipped for sake of brevity
if downloadmessage = "loading" then
progressmessage trunc(trunc(recvd/1024)/trunc(bytesTotal/1024) *100) &"% downloaded"
end if

end urlProgress

My progressmessage handler shows a black, round rect, 30% blended graphic that has it's name visible (and set to white), which I set to whatever text I want.

Example here:

http://dl.dropbox.com/u/67170/examples/progress.jpg

If I need a progress bar, I use MobUI.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Loading Video from URL

Post by Jellicle » Tue Aug 30, 2011 3:57 am

It does support libUrlDownloadToFile though.

g
14" MacBook Pro
Former LiveCode developer.
Now recovering.

digifilm
Posts: 12
Joined: Sat Mar 12, 2011 5:44 pm
Contact:

Re: Loading Video from URL

Post by digifilm » Tue Aug 30, 2011 6:19 am

Thanks Gerry. I will work with this now.

-dd

digifilm
Posts: 12
Joined: Sat Mar 12, 2011 5:44 pm
Contact:

Re: Loading Video from URL

Post by digifilm » Wed Aug 31, 2011 7:30 pm

This line is returning a divided by zero error. Is this normal.

Code: Select all

trunc(trunc(recvd/1024)/trunc(bytesTotal/1024) *100) &"% downloaded"
Thanks,
-dd

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Loading Video from URL

Post by Jellicle » Wed Aug 31, 2011 10:32 pm

No, it's not normal to do that. Show us more of your code - I pass the value derived from that calculation to my progressmessage handler - what are you doing with it? And are you declaring those parameters in your handler?

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

digifilm
Posts: 12
Joined: Sat Mar 12, 2011 5:44 pm
Contact:

Re: Loading Video from URL

Post by digifilm » Thu Sep 01, 2011 12:02 am

ok. Figured it out. Thanks Gerry.

colourpixels
Posts: 83
Joined: Mon Oct 31, 2011 5:28 am

Re: Loading Video from URL

Post by colourpixels » Wed Jan 18, 2012 7:04 am

I've been trying to use:

Code: Select all

 libUrlDownloadToFile "http://website.com/movie1.mp4"
to download a movie, which is working but the IOS screen is locked for the duration of the download (meaning I can't even update a progress bar). Is that normal or am I doing something wrong?

my progress bar update live here:

Code: Select all

on urlProgress pUrl, pMessage,pbytesR,pbytesT
   
    if pMessage contains "loading" then
      set the uValue of grp "Progress" to ((pbytesR/pbytesT)*100)
     
   End if
end urlProgress
Which is firing, 'cause when I through an Ask dialogue box in the that shows, but other than that my screen goes black. Any thoughts?

Many thanks for any help

Dale

Post Reply