Time for action – setting up the Media card scripts

Copy the functions that you have proved to work, in the test stack script and paste them into the WebScraper stack script. Then, perform these steps:

  1. Go to the Media card. As with the Links card, we're not going to add any controls to the card, as we'll do that with the script. So, edit the card script.
  2. Here's the Media card's init function and the needed global variables:
    global gPageHTML,gMediaList
    
    on init
      if the platform is "iphone" or the platform is "android" then
        put getMedia(gPageHTML) into gMediaList
        if the number of lines in gMediaList = 0 then
          answer "There is no media in this page!"
        else
          set the itemdelimiter to "/"
          put empty into tMediaNames
          repeat with a = 1 to the number of lines in gMediaList
            put the last item of line a of gMediaList into line a of tMediaNames
          end repeat
          mobilePick tMediaNames,1
          if the result > 0 then
            put the result into tMediaLine
            showMedia line tMediaLine of gMediaList
          end if
        end if
      end if
    end init
  3. Unlike the Links case, we've built up a list of just the filename part of the URL, to be seen in a native picker, and when we've selected something we will call a showMedia function in the stack script.
  4. Edit the stack script.
  5. Create the showMedia function:
    on showMedia pMediaFile
      if there is an image "mediaImage" then delete image "mediaImage"
      set the itemdelimiter to "."
      switch (the last item of pMediaFile)
        case "png"
        case "gif"
        case "jpg"
        case "jpeg"
          new image
          set the name of image the number of images to "mediaImage"
          set the filename of image "mediaImage" to pMediaFile
          break
        case "mp4"
        case "m4v"
        case "mov"
        case "mp3"
          set the showController of the templatePlayer to true
          play video pMediaFile
        break
      end switch
    end showMedia
  6. Test the app.
  7. You can start with the google.com page; click on the Media tab button to see a list of the images used on that page.
  8. Select an image from the list and click on Done.
  9. The image should appear on the card.
  10. Go back to the Browser card and change the URL to http://www.apple.com/.
  11. Apple usually includes some video link thumbnails on the main page. click on one of those, so that you see the large video player. However, don't play it!
  12. Click on the Media tab button to see a list of all the media on that page.
  13. Scroll down the list and look for one of the longer-named items that seems like it must be a video.
  14. Select that item and press Done. The video should load and play on the card.
  15. Use the video controller's Done button when you are finished watching the video to return to the Media card.
  16. You can then click on the Media tab button again to make the picker reappear.
  17. Go back to the Browser card and enter a URL that contains examples of MP3 files. http://www.ntonyx.com/mp3_songs.htm is one such example.
  18. Click on the Media tab button to return to the Media card with the list of all the media on that page, which in this case will be mainly MP3 files.
  19. Select one of the MP3s from the list and click on Done. The MP3 should play in the same player that the video is played in.

What just happened?

In this example, we made use of both a standard LiveCode control, the image, and also a native control, the video player. LiveCode handles the setting up of the player and with the very simple "play video videoname" syntax, we were able to invoke the native player. It was able to play both video and audio files.

The Keepers card

Actually, this should be the Keepers cards. These cards are where you can stash media that you've found interesting. For file size reasons, we're actually just going to store the URL to the media; after all, a long video would soon use up your device's storage!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset