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"
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
in to the second invisible video. Reason is I want to preload the video before it gets active and is played.mobileControlSet tPlayer2, "filename", tData[sNextPos]["location"]
* 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