I create Looping video.
I want to use function callbacks to another stack.
Here my code :
start using stack "Widget Project"
put the duration of player "Player" into tDuration
put tDuration & ",restartPlayer" into tCall
set the callbacks of player "Player" to tCall
You don't need to use callbacks if you want to execute a script when a movie finishes playing. You can use the playStopped message:
on beforeYouStartPlayingTheMovie
start using stack "Widget Project"
end beforeYouStartPlayingTheMovie
-- in stack "Widget Project"
on playStopped
if the id of the target is the id of player "Player" of stack "Your Stack" then
-- do whatever you want here
end if
pass playStopped
end playStopped
Use the playerFinished message on iOS and Android.
Related
In my Corona SDK project, I have a composer scene called "menu.lua" (created with composer.newScene()) that is the first scene, called by main.lua file. I have a background track only for this scene, loaded in scene:create() with audio.loadSound() in a local variable. When I load another scene (let's suppose it's a "credit" scene, static, with no music, sounds, animations, timers, etc.) and then come back to menu scene, audio is still played, but with a lower volume.
Audio is played in loop on channel 2, I use audio.play() in scene:show "did" phase. I use audio.fadeOut() in scene:hide "will" phase, and stop it with audio.stop() in "did" phase, then dispose it with audio.dispose() in scene:destroy.
In "menu.lua" file
local composer=require("composer")
local scene=composer.newScene()
local theme --this is the variable for audio
function scene:create(event)
local sceneGroup=self.view
theme=audio.loadSound("sfx/theme_short.mp3")
end
function scene:show(event)
local sceneGroup=self.view
if event.phase=="will"
audio.play(theme,{loops=-1,channel=2})
end
end
function scene:hide(event)
local sceneGroup=self.view
if event.phase=="will" then
audio.fadeOut(theme,{500})
end
elseif event.phase=="did" then
audio.stop(2)
end
end
function scene:destroy(event)
local sceneGroup=self.view
audio.dispose(theme)
end
The other scene (let's suppose it's "credits.lua") is called by a button with a "tap" event attached. In "credits.lua" I use this function to go back to "menu.lua" scene (function is called with a "tap" event attached to a button)
local function goMenu()
composer.removeScene("menu")
composer.gotoScene("menu","slideUp",500)
return true
end
I've already tried to play audio in scene:show "did" phase and in scene:create, but the problem persists. The problem happens with all the scenes, all static (3 in total). Any idea?
You should replace
audio.fadeOut(theme,{500})
with
audio.fadeOut( { channel=2, time=500 } )
since you use wrong syntax.
See audio.fadeOut()
Make sure you read the "Gotcha" section of the docs:
When you fade the volume, you are changing the volume of the channel. This value is persistent and it's your responsibility to reset the volume on the channel if you want to use the channel again later (see audio.setVolume()).
You're responsible for setting the channel volume back because fadeOut changes the volume of the channel.
I'm using the SpotifyAPI-NET on GitHub from JohnnyCrazy to play and pause songs on my Spotify desktop client. This works fine.
Now I want to change the playing position of the currently playing song. So I only want to say something like "SetPlayingPosition(64)" to play the current song from position "01:04". It seems that the SpotifyLocalAPI didn't support this feature.
To play and pause a song the API uses a message with the following format:
http://127.0.0.1:4381/remote/pause.json?pause=true&ref=&cors=&_=1520448230&oauth=oauth&csrf=csrf
I tried to find a summary of possible commands in this format, but I didn't find anything.
Is there something like http://127.0.0.1:4381/remote/seek.json... that I can use to seek to a specific position?
EDIT:
I tried to write my own method in the RemoteHandler class in the local portion of the SpotifyAPI. With this method I can set the position in the current playback.
Here's my code:
internal async Task SendPositionRequest(double playingPositionSec) //The desired playback position in seconds
{
StatusResponse status = GetNewStatus(); //Get the current status of the local desktop API
string trackUri = "spotify:track:" + status.Track.TrackResource.ParseUri().Id; //The URI of the current track
TimeSpan playingPositionTimeSpan = TimeSpan.FromSeconds(playingPositionSec);
string playingPosStr = playingPositionTimeSpan.ToString(#"mm\:ss"); //Convert the playingPosition to a string (Format mm:ss)
string playingContext = "spotify:artist:1EfwyuCzDQpCslZc8C9gkG";
await SendPlayRequest(trackUri + "#" + playingPosStr, playingContext);
if (!status.Playing) { await SendPauseRequest(); }
}
I need to call the SendPlayRequest() method with the correct playingContext because when the current song is part of a playlist and you call SendPlayRequest() without the context, the next song isn't from the playlist anymore.
But you can see that I use a fixed context at the moment.
So my question is now: How can I get the context (playlist, artist, ...) of the currently played song with the SpotifyLocalAPI?
The SeekPlayback method of the library you mentioned lets you seek through playback on whatever device your user is listening on. You can find the docs here.
Seeking playback is not currently possible using the Spotify Local API portion of that library.
I'm writing a script that will fill in a form in Microsoft Edge. I know I should use WinActivate to change focus, but I don't know how to find out what the argument should be? For example if I go to Stackoverflow I can sort of guess it would be like Stack Overflow - Microsoft Edge but if the title is longer it gets truncated in the toolbar and I honestly don't know where I can go to see the full title of a process? I tried Task Manager.
Is there a better way? It seems a bit hacky to rely on the title of the program, especially when the title of the website determines it.
Basically I'm asking, how do you use WinActive to change focus?
Process, Exist, MicrosoftEdge.exe
EdgePID = %ErrorLevel%
if( EdgePID )
{
MsgBox, Edge is running, with PID: %EdgePID%
}
WinGetTitle, Title , ahk_pid %EdgePID%
MsgBox, Title: %Title%
IfWinExist, %Title%
WinActivate ; this doesn't work
You can use the process name which should be always the same. I'm assuming the name for Microsoft Edge is MicrosoftEdge.exe, change it if your process is named differently.
First get the process PID, which is stored in ErrorLevel:
Process, Exist, MicrosoftEdge.exe
EdgePID = %ErrorLevel%
if( EdgePID
{
MsgBox, Edge is running, with PID: %EdgePID%
}
Then get the window title of that process, using the special command ahk_pid:
WinGetTitle, Title , ahk_pid %EdgePID%
MsgBox, Title: %Title%
The window can be activated using the same method:
WinActivate, ahk_pid %EdgePID%
Alternatively the process name can be used directly:
WinActivate, ahk_exe MicrosoftEdge.exe
My friend and I have been working on a game in love2d recently, but in the early stages of developing my computer hard drive stopped working meaning only my friend could work on it. Now I have a computer and I want to make a main menu in Love2d but There is alot of code in the love.load function (generation of the world and such). My question is can I change what is in love.load when the game is running? e.g The main menu loads up, then the generation of the world loads up when the start button is pressed.
The love.load function runs only once. As you mention, it's generally used to set up data structures and pre-load other resources. You can use it to handle both the world pre-load and the menu pre-load. Then, control what is active via some sort of state. A simplified example:
local state = "menu"
function love.load()
preLoadMenu()
preLoadWorld()
end
function love.update(dt)
if state == "menu" then
updateMenu()
else
updateWorld()
end
end
function love.draw()
if state == "menu" then
drawMenu()
else
drawWorld()
end
end
function love.mousepressed(x, y, button)
if startClicked(x,y,button) then
state = "world"
end
end
It's conceivable that you won't want to pre-load absolutely everything for your game on load. Maybe your game is just too big. If that's the case, consider working with an active scene. A scene might be the menu or maybe it's a game level. Again, a simplified example:
local currentScene
function love.load()
currentScene = loadMenu()
end
function love.update(dt)
currentScene.update(dt)
end
function love.draw()
currentScene.draw()
end
function love.mousepressed(x, y, button)
if startClicked(x,y,button) then
currentScene = loadWorld()
end
end
This second option is much more flexible in the long run. It can handle any number and type of scenes without conditional logic for each. It will require a little "object" thinking. All scenes need a consistent way to update and draw.
If your world takes a while to load, you may want to display a temporary "world is loading" scene so your users don't get impatient.
For example, I'm adding a menu and want to set it's priority.
setHandlerPriority checks if the menu is associated with a touch handler and it fails because addition is scheduled on next loop(pushed onto a queue).
How can I add a menu(as a child) and set its priority at the same time?
Or how can I call the 'setHandlerPriority' on next loop?
Does 'runAction' with 'CCCallFunc' execute the function on next frame?
Thank you
you can create a sequence of actions.
those actions can be a CCDelayTime or CCCallFunc, then they can be called with the order you want it to be. just use any CCNode to run that action.