Sleep Timer Button for a streaming player AS3 - android

I am doing Android app using Flash CS6 and Adobe AIR. It is a simple streaming radio player with one button for play and stop. I would like to add a new button with a timer function (sleep) that stops the player or exit the app) after 30 minutes. How could I add this?
Here is the code I am using (works fine):
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);
var fl_SC:SoundChannel;
var fl_ToPlay:Boolean = true;
function fl_ClickToPlayStopSound(evt:MouseEvent):void
{
if(fl_ToPlay)
{
var s = new Sound(new URLRequest("http://myradio.com/stream.mp3"));
fl_SC = s.play();
}
else
{
fl_SC.stop();
}
fl_ToPlay = !fl_ToPlay;
}

Create another button for this.
Initialize a timer variable default as 0
Add event listeners to your new button for "CLICK" event and "ENTER_FRAME" event both.
Use your timed button's "CLICK" event for setting your timer variable's value to 30 minutes(depends on your framerate) & adding your button "ENTER_FRAME" event listener.
Use your timed button's "ENTER_FRAME" event to countdown your timer variable & check for is it "less than 0" & then run your sleep function & remove event listener "ENTER_FRAME"
I don't want to give you any code, that's not lookin fair for a question easy like that, check for tutorials, you can find lots of ways to solve something like that...

I have found a solution. I've linked the button to a new frame with the following code:
var s = new Sound(new URLRequest("http://myradio.com/stream.mp3"));
fl_SC = s.play();
var fl_TimerInstance_2:Timer = new Timer(900000, 1);
fl_TimerInstance_2.addEventListener(TimerEvent.TIMER, fl_TimerHandler_2);
fl_TimerInstance_2.start();
var fl_SecondsElapsed_2:Number = 1;
function fl_TimerHandler_2(event:TimerEvent):void
{
fl_SC.stop();
}
It works perfect.
Thank you very much for your help.
Regards

Related

How to change the MiniController button if is live streaming

I need to show a play/stop toggle instead of a play/pause button when we are casting live content to the chromecast, but we still need the play/pause when casting other videos.
I set the minicontroller casting buttons to a custom button where in the onResume I called my function that bound different drawables depending on what is being casted. The problem is that when I change the video to live (or other way around) on a page with a already showing minicontroller it doens`t call onResume again (rightfully so), and it keeps the same buttons. I don't know if there is another event inside minicontroller that I can use. I try to use SessionManagerListener and a UiController to bound my functions to certain events but both of them there were problems (I probably did something wrong, dont know).
My function is:
fun checkButton() {
activity?.let {
val mCastContext = CastContext.getSharedInstance(activity!!.baseContext)
val mCastSession = mCastContext.sessionManager.currentCastSession
if (mCastSession?.remoteMediaClient?.currentItem != null) {
val drawablePlay = ContextCompat.getDrawable(it, R.drawable.cast_ic_mini_controller_play)
val drawableStop = ContextCompat.getDrawable(it, R.drawable.cast_ic_mini_controller_stop)
uiMediaController.bindImageViewToPlayPauseToggle(button, drawablePlay!!, drawableStop!!, drawableStop, ProgressBar(it), false)
}
}
}
I expect to call my function every time the miniController loads or something like that.
Thanks!
Found it... looks like uiMediaController.bindImageViewToPlayPauseToggle already do this automatically, it already has the logic to use the stop button when is live streaming...

Focus html page or element from a webview with talckback

I have an hybrid app developed with ionic 1.x. When the app loads I am forcing the webview to take the focus from native side with the hope that after some initialization request a survey dialog appear and take the focus it self(When dialog appear I am forcing it to take focus). I am trying to make it work with talkback
The problem is that when you load the app from scratch the dialog is not focused so it is not read, after navigate through the app and come back to the original page then in works as expected, looks like as the user is in fact inside the page things works ok.
Is there any workaround or strategy to solve this particular situation?
Thanks in advance
I don't know if it helps you,
but we use it to focus on specific elements in the web view.
it works in android and ios,
but in android, before every element it read webview.
(if you found a solution for it please let me know)
function putFocus(elementForFocus) {
var $element = $(elementForFocus);
var focusInterval = 10; // ms, time between function calls
var focusTotalRepetitions = 10; // number of repetitions
$element.attr('tabindex', '0');
$element.blur();
var focusRepetitions = 0;
var interval = window.setTimeout(function () {
$element.focus();
}, focusInterval);
};

Why fastforward/rewind button first time working too slow

I am working on video player using video node. My issue is when i press first time fastforward/rewind button during video playing/buffering then button is not working. After pressing 4-6 times fast forward or rewind button is working after that it is working properly but for first time i have to press 4-6 time button then working. My code is...
function setVideo()
m.InnerVideo = m.top.createChild("InnerVideo")
inner = createObject("RoSGNode", "ContentNode")
inner.url = "url..."
inner.streamformat = "hls"
m.innerVideo.visible = true
m.innerVideo.content = inner
m.innerVideo.control = "play"
end function
Event handler code is...
function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press
if key = "fastforward"
print "fastforward"
handled = true
end if
end if
return handled
end function
Please suggest me what should be issue? Is issue related to video file format or encoding/decoding or others?
On onKeyEvent Function, you print above of handled = false "?key" value and check which value print in here. and also check "?press" if true then pressed key and false then not pressed. Here the Best way to whatever happening in your onKeyEvent Function. Like below
function onKeyEvent(key as String, press as Boolean) as Boolean
? "Key Event is about to execute - key = "key " press = " press
end function
If prints from onKeyEvent are printed after 5th or 6th time maybe You have a problem with focus. It could be that You player is not in the focus at first and then at some point You assign a focus to it.
Try to add: m.InnerVideo.setFocus(true) in your setVideo() function.
If it does not work check if there is something else that is taking the focus off the m.InnerVideo after setVideo() function is executed.

CORONA SDK: Create a back to main button stopping the already started scenes.

im developing an APP in corona SDK, it's a serie of tests, so i made every test separately and then i created a main Scene that contains this tests. To handle any click error or misunderstanding i created a "back to intro" button, the problem is, when i start a test (for example test2) i'm in the middle of the test and i use the back to intro button (that takes me to intro, there's no prob with that) the Test2 keeps going and when i try to re-take the test shows an error related to this. I've trying different ways but i can't make it work, here is the code of the button:
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
storyboard.showOverlay( "cerrar sesion", options )
end
end
local button1 = widget.newButton
{
width = 60,
height = 60,
defaultFile = "images/boton_config.png",
overFile = "images/boton_config.png",
label = "",
onEvent = handleButtonEvent
}
-- Center the button
button1.x = display.contentCenterX+550
button1.y = 35
button1.isVisible=true;
storyboard.gotoScene("test0intro")
Plz help :<
I think I may have had this problem. I would advise switching to composer rather than storyboard a lot of these issues are easier to find. I am unsure about storyboard but for composer I know that I had to remove all event listeners, remove the sceneGroup, stop the physics and then remove the scene in the scene:hide method. I'm unsure of what the equivalent of this is in storyboard. Otherwise when I went to restart to the game (as you seem to be doing), the game would crash. Hope that helps!

How can I wait for button click in android?

I'm about to finish my Simon Says game, but I still have one crucial problem.
After my buttons are shown to the player, I have to wait (according to the level, e.g, if 5 buttons were showed to the user, I have to wait the user to click 5 buttons). I have searched around the internet, but the only answer was "You cannot freeze the android Application... blah blah blah".
Here it is my code:
public boolean playerTurn(){
//Enable buttons
buttonUp.setClickable(true);
buttonDown.setClickable(true);
buttonRight.setClickable(true);
buttonLeft.setClickable(true);
/*
Wait for a button clicks depends on the level, but HOW?
e.g, if the level is 5, I have to wait for 5 button clicks
and after it, I can continue to run the code
*/
/*Check if the user typed the correct order
*If pressed the correct order
*return true;
*else
*return false
*/
}
For each button do something like this:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
buttonsPressedCount++;
if (buttonsPressedCount >= 5) {
// Do whatever you wanted to do
}
}
});
In this way, each button will listen for clicks and update a global counter. Finally when your global counter is greater than 5, you can proceed. The application is never "paused", it just only moves on the next section when five buttons have been clicked.
I'm not near a computer so no code example (will post later). Basically, you can set a class level counter. Provide an OnClickListener for each button - can be same or different. In the listener increment the counter and check if it reached 5 or not. If it did, check the pattern and clear counter.
You can use RxBindings for this purpose. Convert the clicks into a stream of events, and add a subscriber to it, which will react to the event of a click.
Here's how you can do it,
RxView.clicks(button)
.take(5)
.subscribe(aVoid ->
{
// Do your stuff
});
This will add a subscriber to the click event, and will only take the first five events.
Hope it helps.

Categories

Resources