Page 1 of 1

Problem with Players

Posted: Sat Mar 01, 2014 9:42 pm
by charms
Hello,

I have some issues with the Video Player. I'm trying to create a Media Player that rotates between two cards and loads an element of an array that contains the path of videos and images that will be loaded. First I have set the visible to false, loaded the new file and then set the visible to true again. This worked on MacOS but on Android the Video was freezing. According to one of your employees the Video object has to be deleted on Android before playing the next video. So I have decided to always delete the player and create a new one. Not only the Android Player but also the MacOS Player.

Now the problem is that when I delete the object it works the first time when I open the card. But if I open the card again the player shrinks to a small square. I assume this happens when an error has occurred.

Can you answer following questions?
* Should it work to delete and re-create a player on MacOS in the code? Or is it intended to create one player that will be made visible/invisible?
* Why is the player shrinking to a small square, even though I have defined it to scale to the size of the card?
* Why is it working the first time when I load the livecode file but when I close it and try another time I see the video in a small square?

It seems like randomly when I open the livecode file the video is once a small square and once it's scaling again. I have now tested with rotation and most of times when I open the file the first time the video is showing as small square but as soon the next movie plays the then everything is scaling correctly. Seems like sometimes the code is not fully executed when opening the file. Or at least the width and height are not set yet.

I have added a wait 5 seconds to the OpenStack section and with this it works. This does it as a work around but I'm not sure if this is really the final solution.

I'm using LiveCode Commercial 6.5.2.

Thanks for your help.

Code: Select all

on OpenStack

end OpenStack

on OpenCard
   startVideo
   wait 5 seconds
   stopVideo
end OpenCard

on resizeStack
   resizeVideo
end resizeStack

on startVideo
   if the environment is "mobile" then
   else
      if exists(player "Video") then
         delete player "Video"
      end if
      
      create player "Video"
      set the width of player "Video" to the width of this card
      set the height of player "Video" to the height of this card
      set the top of player "Video" to 0
      set the left of player "Video" to 0
      set the lockLoc of player "Video" to true
      set the showBorder of player "Video" to false
      set the filename of player "Video" to "/Users/charms/Documents/LiveCode/testdata/videos/1.mp4"
      start player "Video"
   end if
end startVideo

on stopVideo
   if the environment is "mobile" then
   else
      if exists(player "Video") then
         delete player "Video"
      end if
   end if
end stopVideo

on resizeVideo
   if the environment is "mobile" then
   else
      if exists(player "Video") then
         set the width of player "Video" to the width of this card
         set the height of player "Video" to the height of this card
      end if
   end if
end resizeVideo


Re: Problem with Players [unsolved]

Posted: Sun Mar 02, 2014 2:17 am
by Simon
Hi charms,
I'm not sure about why the wait 5 seconds in the openCard fixes it, not even sure it does.
Here the trick was to put

Code: Select all

      set the filename of player "Video" to "/Users/charms/Documents/LiveCode/testdata/videos/1.mp4"
       wait 1 tick --add this
      start player "Video"
into the code and it works well.
According to one of your employees..
Just so you know most of us here are volunteers. :)

Simon

Re: Problem with Players

Posted: Sun Mar 02, 2014 2:51 am
by charms
Hi Simon,

Thanks, you guys are great. Regardless if you are employees or volunteers... I've been working with Bash, Perl, Java (Spring, J2EE), JavaScript (JQuery, AngularJS), PHP, Ruby on Rails but I have never experienced a such excellent support, I have never experienced such an easy way to build an application and such a functional Framework as with LiveCode and it's community. I hope I'll be able to participate soon.

It's actually the first time I feel happy to develop an application and my frustration level has never been so low :)

One evening, a bottle of wine, help from you guys and my player is running.

Kind regards,
Chris

Re: Problem with Players

Posted: Sun Mar 02, 2014 1:57 pm
by Klaus
Hi Chris,

here some general hints:

Do not check for a condition, that is not neccessary:

Code: Select all

on startVideo
   if the environment is "mobile" then
   # EMPTY condtion
   else
    ## do something
  end if 
Does not make much sense, so better check like this in your case:
1. Leave handler in unwanted case, my favourite, much better readable!:

Code: Select all

...
if the environment is "mobile" then
    exit stopvideo
  end if
## do other DESKTOP stuff here...
...
2. Or avoid ELSE where not neccessary:

Code: Select all

...
   if the environment <> "mobile" then
       if exists(player "Video") then
         delete player "Video"
      end if
 ...
Save some typing by setting the RECT instead of left, top, width and height separately:

Code: Select all

...
create player "Video"
set the rect of player "Video" to the rect of this card
## Done :-)

# set the width of player "Video" to the width of this card
# set the height of player "Video" to the height of this card
# set the top of player "Video" to 0
# set the left of player "Video" to 0

set the lockLoc of player "Video" to true
...
And I, personally, would use a pre-build player object and not create a new one every time! 8)


Best

Klaus

Re: Problem with Players

Posted: Sun Mar 02, 2014 9:58 pm
by jacque
charms wrote:Hi Simon,

Thanks, you guys are great. Regardless if you are employees or volunteers... I've been working with Bash, Perl, Java (Spring, J2EE), JavaScript (JQuery, AngularJS), PHP, Ruby on Rails but I have never experienced a such excellent support, I have never experienced such an easy way to build an application and such a functional Framework as with LiveCode and it's community. I hope I'll be able to participate soon.

It's actually the first time I feel happy to develop an application and my frustration level has never been so low :)
This reminds me of how I felt when I first started. You made me smile. Thank you for that. :)