如何在运行时创建播放器并使用代码设置自动播放?

时间:2014-05-05 09:56:00

标签: livecode

我想从另一个堆栈创建一个视频播放器并设置自动播放。

我创建了对象"播放器"在堆栈2中创建一个播放器,我点击一个按钮。

这是按钮中的代码:

set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"

此代码正常运行。但是玩家没有自动播放。

1 个答案:

答案 0 :(得分:0)

你需要在复制后启动播放器。

set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
start player myNumberOfPlayers of card "object" of stack "stack2"

有时在完成处理程序后发送播放命令可能是个好主意:

set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
send "startPlayer myNumberOfPlayer" to me in 0 millisecs

on startPlayer thePlayerNumber
   start player thePlayerNumber of cd "object" of stack "stack2"
end startPlayer

复制后设置文件名也是一个好主意:

copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
set the filename of player myNumberOfPlayer of card "object" of stack "stack2" to "myurl"
send "startPlayer myNumberOfPlayer" to me in 0 millisecs

on startPlayer thePlayerNumber
   start player thePlayerNumber of card "object" of stack "stack2"
end startPlayer

如果你想在卡片打开时自动开始播放播放器控件,只需将start player命令放入card" object"的卡片脚本中的openCard处理程序中。 stack" stack2":

on openCard
  put the number of players into myNumberOfPlayers
  if myNumberOfPlayers > 0 then
    start player myNumberOfPlayers
  end if
end openCard