mobileControlSet

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

mobileControlSet

Post by charms » Sun Feb 23, 2014 3:14 pm

Hello,

I have following questions:

Question1
I load an mp4 video from the sdcard like seen below.
The video starts to play but I only hear the sound and see the rectangle with black background instead of the picture. The video however plays perfectly with the android media player.

* What could be the reason that there is only a black screen? Could it be an issue with the size? The video is 1920x1080 and there are black stripes at top and bottom. But I assume that the video is resized when I define the size of the rectangle?

Code: Select all

      mobileControlCreate "player", "Player1"
      put the result into tPlayer1
      mobileControlSet tPlayer1, "visible", true
      mobileControlSet tPlayer1, "rect", "0,0,400,250"
      mobileControlSet tPlayer1, "filename", "/storage/sdcard0/Media/videos/1.mp4"
      mobileControlSet tPlayer1, "visible", true
      mobileControlDo tPlayer1, "play" 
Question2
The complete code is a little more complex however.
I'm initializing the Video in the on openStack command and write the result in a local variable called tPlayer1 and tPlayer2. Then in the openCard command I load the first video and while the first video is playing visible I load the next video with
mobileControlSet tPlayer2, "filename", tData[sNextPos]["location"]
in to the second invisible video. Reason is I want to preload the video before it gets active and is played.

* Could this be a possible reason for the black screen?
* Is this actually the right way to preload videos on an Android device?

Please note that these are only snippets from the complete code.

Code: Select all

local tPlayer1
local tPlayer2

on openStack
      -- create Player1
      mobileControlCreate "player", "Player1"
      put the result into tPlayer1
      mobileControlSet tPlayer1, "visible", false
      mobileControlSet tPlayer1, "rect", "0,0,400,250"

      --create Player2
      mobileControlCreate "player", "Player2"
      put the result into tPlayer2
      mobileControlSet tPlayer2, "visible", false
      mobileControlSet tPlayer2, "rect", "0,0,400,250"
end openStack

Code: Select all

on openCard
      repeat forever
         -- get the current and next array positions
         if tPos is tDataLength then
            put tPos into sCurPos
            put 0 into sNextPos
         else if tPos > tDataLength then
            put 0 into tPos
            put 0 into sCurPos
            put tPos + 1 into sNextPos
         else
            put tPos into sCurPos
            put tPos + 1 into sNextPos
         end if
         
         -- output the positions in to a text field for debugging
         set the text of field "position" to "tPos: " & tPos & ", sCurPos: " & sCurPos & ", sNextPos: " & sNextPos
         
         if sShowMedia is 1 then
            -- display current pos
            if tData[sCurPos]["type"] is "image" then
               set the visible of image "Image1" to true
               set the visible of image "Image2" to false
            else if tData[sCurPos]["type"] is "video" then
               set the visible of image "Image1" to false
               set the visible of image "Image2" to false
               mobileControlSet tPlayer1, "visible", true
               mobileControlDo tPlayer1, "play" 
               put "Playing Video 1" into field "status"
            end if
            
            -- load next pos
            if tData[sNextPos]["type"] is "image" then -- if media is an image
               set the filename of image "Image2" to tData[sNextPos]["location"]
            else if tData[sNextPos]["type"] is "video" then -- if media is a video
               mobileControlSet tPlayer2, "filename", tData[sNextPos]["location"]
            end if
         else
            -- display current pos
            if tData[sCurPos]["type"] is "image" then
               set the visible of image "Image2" to true
               set the visible of image "Image1" to false
            else if tData[sCurPos]["type"] is "video" then
               set the visible of image "Image2" to false
               set the visible of image "Image1" to false
               mobileControlSet tPlayer2, "visible", true
               mobileControlDo tPlayer2, "play" 
               put "Playing Video 2" into field "status"
            end if
            
            -- load next pos
            if tData[sNextPos]["type"] is "image" then -- if media is an image
               set the filename of image "Image1" to tData[sNextPos]["location"]
            else if tData[sNextPos]["type"] is "video" then -- if media is a video
               mobileControlSet tPlayer1, "filename", tData[sNextPos]["location"]
            end if
         end if
         
         -- wait until the length of the media has been reached
         wait tData[sCurPos]["length"] seconds
    end repeat
end openCard

-- load test data
on loadTestData
   put empty into tData
   
   -- Image 1
   put "1" into tData[0]["id"]
   put "image" into tData[0]["type"]
   put "6" into tData[0]["length"]
   put "FullHDImg1" into tData[0]["name"]
   put "/storage/sdcard0/Media/images/fullhdImg1.jpg" into tData[0]["location"]
   
   -- Image 2
   put "2" into tData[1]["id"]
   put "image" into tData[1]["type"]
   put "6" into tData[1]["length"]
   put "FullHDImg2" into tData[1]["name"]
   put "/storage/sdcard0/Media/images/fullhdImg2.jpg" into tData[1]["location"]
   
   -- Image 3
   put "3" into tData[2]["id"]
   put "image" into tData[2]["type"]
   put "10" into tData[2]["length"]
   put "FullHDImg3" into tData[2]["name"]
   put "/storage/sdcard0/Media/images/fullhdImg3.jpg" into tData[2]["location"]
   
   -- Video 1
   put "4" into tData[3]["id"]
   put "video" into tData[3]["type"]
   put "30" into tData[3]["length"]
   put "FullHDImg3" into tData[3]["name"]
   put "/storage/sdcard0/Media/videos/1.mp4" into tData[3]["location"]
   
   -- count number of lines in array
   put the number of lines of keys of tData -1 into tDataLength
Last edited by charms on Fri Feb 28, 2014 12:12 am, edited 2 times in total.

ChrisMukrow
Posts: 73
Joined: Mon Nov 12, 2012 4:13 pm

Re: mobileControlSet

Post by ChrisMukrow » Sun Feb 23, 2014 8:40 pm

There was a bug in Livecode/Android that videos stayed black and only played with sound. We had this problem with Youtube videos, I don't know if this bug has been fixed, what version are you using?

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: mobileControlSet

Post by charms » Sun Feb 23, 2014 9:24 pm

This seems to be a redraw problem. When I click the home button to leave the app and then go in to the task again the video is displaying. This is really strange.

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: mobileControlSet

Post by charms » Sun Feb 23, 2014 9:27 pm

Hi Chris I'm using 6.5.2. Seems to be a redrawing issue. When I leave the app (not close only push the button to get back to the android desktop) and then select the app again from the task list the video is playing.

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: mobileControlSet

Post by charms » Mon Feb 24, 2014 7:46 pm

Ok, it seems the problem appears under certain circumstances when two video layers are on top of each other. When I move one of the video layers next to the other layer both videos play correctly. This looks like a redraw bug.

After some research I found the following control: mobileControlSet tPlayer2, "alwaysBuffer", true. If I set this then the redraw bug vanishes and both video layers work on top of each other.

I have decided to move back to the two card setup I had where there is a switch between two cards. Reason is also that visual effects are working with images but not with mobileControlSet elements. So I need to set the visual effects on the card.

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: mobileControlSet

Post by charms » Thu Feb 27, 2014 11:57 pm

I still have issues. When I play a video and stop it after a certain time, go to the next card, load a new video in to the same local variable and start it again then I see a frozen picture of the stopped video while hearing the sound of the new started video.

My next approach to get this to work is to delete the mobile player object and add it again. But it's pretty hacky.

Does anybody else experience such issues? Or am I the only one?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: mobileControlSet [unsolved]

Post by Simon » Fri Feb 28, 2014 12:02 am

Hi charms,
You are supposed to delete the video player when you go from one card to the next.
Same thing with the browser object.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: mobileControlSet [unsolved]

Post by charms » Fri Feb 28, 2014 12:11 am

Hi Simon,

Ok, thanks. Will implement it that way.

Kind regards,
Chris

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: mobileControlSet

Post by Dixie » Fri Feb 28, 2014 1:36 am

You don't have to 'delete' a mobile control if you move between cards !...

You can choose to just make the control invisible when you leave a card and make it visible again when you come back to the card...

for example, this is particularly useful when using a 'scroller', as you can maintain the position of the scroll without having to save it and set the scroll again if you build it 'everytime' you visit a particular card...

rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Mon Oct 08, 2012 11:30 am

Re: mobileControlSet

Post by rmuzzini » Thu Nov 20, 2014 10:40 am

charms wrote:This seems to be a redraw problem. When I click the home button to leave the app and then go in to the task again the video is displaying. This is really strange.
i had the same problem. a single video, android app, sound ok, video hidden, magically appearing on quitting.
after a few tests (with LC 6.6.5, 6.7, 7.0) i found the guilty line:

on openStack
set the acceleratedRendering of this stack to true //bad bad bad!

end openStack

commented out, videos start to play fine.

i post here my solution, maybe usefull for others in the future…
[btw, it seems a bug to me…]

Post Reply