Page 1 of 2

Loading Video from URL

Posted: Mon Aug 29, 2011 12:06 am
by digifilm
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

Re: Loading Video from URL

Posted: Mon Aug 29, 2011 5:12 am
by Jellicle
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

Re: Loading Video from URL

Posted: Mon Aug 29, 2011 6:18 am
by digifilm
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

Re: Loading Video from URL

Posted: Mon Aug 29, 2011 8:03 am
by Jellicle
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

Re: Loading Video from URL

Posted: Mon Aug 29, 2011 6:24 pm
by FourthWorld
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.

Re: Loading Video from URL

Posted: Mon Aug 29, 2011 9:28 pm
by digifilm
Hi Richard. So good to see you too. It is very nostalgic. Happy to be back. :D

Re: Loading Video from URL - Progress Bar

Posted: Tue Aug 30, 2011 3:40 am
by digifilm
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

Re: Loading Video from URL

Posted: Tue Aug 30, 2011 3:55 am
by digifilm
Darn. Just figured out. iOS does not support libURL.

Re: Loading Video from URL

Posted: Tue Aug 30, 2011 3:56 am
by Jellicle
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

Re: Loading Video from URL

Posted: Tue Aug 30, 2011 3:57 am
by Jellicle
It does support libUrlDownloadToFile though.

g

Re: Loading Video from URL

Posted: Tue Aug 30, 2011 6:19 am
by digifilm
Thanks Gerry. I will work with this now.

-dd

Re: Loading Video from URL

Posted: Wed Aug 31, 2011 7:30 pm
by digifilm
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

Re: Loading Video from URL

Posted: Wed Aug 31, 2011 10:32 pm
by Jellicle
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

Re: Loading Video from URL

Posted: Thu Sep 01, 2011 12:02 am
by digifilm
ok. Figured it out. Thanks Gerry.

Re: Loading Video from URL

Posted: Wed Jan 18, 2012 7:04 am
by colourpixels
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