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.
Related
I am making a game that changes the color and backgrounds of buttons. When the app opens I run the newGame function. Then after the game ends, to replay the game I recall the newGame function again. However, every time the game is replayed, when a button is clicked, it turns orange for a second before doing what it is supposed to do.
fun newGame() {
allButtons.forEach {
it.text = ""
it.setBackgroundResource(android.R.drawable.btn_default)
it.isEnabled = true
}
gameInProgress = true
}
At other points in the code I'll change the background or enabled property of the buttons using some of the following lines code
button.setBackgroundResource(R.color.zeroColor)
button.setBackgroundResource(R.drawable.flag)
button.isEnabled = false
Any ideas?
I am rather new to android developing and can't figure out how to do a double check on a button press.
I am working in Android Studio and am trying to create a little simple game and have the following: two buttons (button1 and button2)declared and instantiated in an onClick method.
When button 1 is pressed a counter is incremented and a specific value is shown on the button from an array with the values 0, 10, 50, 100.
This part works like a charm. What I can't do is create a working "tiebreaker rule" which should be something like:
if (button1 value == 100 and button2 value == 100) or this can be done with the counter if (counter1 == 3 && counter2 == 3)
tiebreaker();
this is what I need to do:
public void tiebreaker(){
if (button1 is pressed){
button1.setText(String.valueOf("OK. One more!");
if (button1 is pressed (again){
resetCounters();
goForPlayer1(); //distinct method
} else if (button2 is pressed) {
//set both values back to 100
tiebreaker(); //calls itself in order to repeat until a button is pressed twice consecutivelly
} (else?)
if(button2 is presed){
//same code as above, just with the numbers 1 and 2 swapped
}
}
I have tried implementing this tiebreaker method in different ways, but with no final success. I tried with if(button1.isPressed()) as condintion, having a boolean turn true when the button is pressed and using it as a condition, using the values from the buttons with button.equals("100") or whatever should be written but nothing.
Also, I tried making the tiebreaker as a second onClick method and doing checks based on switch (View.getId()) but the problem here is that the method being view dependant (tiebreaker(View v)) I am not sure how to call it from a different method.
IMO the main issue is that if within another if or switch/case within another switch/case can't be used when it comes to button presses (I could be wrong, though), but I don't know of any other way to do this.
I hope I did not miss anything and managed to make myself clear.
I appreciate any input in helping me solve this tiebreaker rule. Thank you
it's probably something like this ...
whenButtonAIsPressed() {
do some stuff
possiblyRunTiebreakerMaterial()
}
whenButtonBIsPressed() {
do some stuff
possiblyRunTiebreakerMaterial()
}
Note that you always run possiblyRunTiebreakerMaterial() and you always run it at the end of doing all your other processing.
Here's the nature of your possiblyRunTiebreakerMaterial() function...
possiblyRunTiebreakerMaterial() {
// there are some conditions, which mean you DO want
// to run the tie breaker:
do some processing, such as
value of A = blah blah
value of B = blah blah
// now have a boolean, and figure it out
boolean shouldWeRunTheTieBreaker
processing
processing
shouldWeRunTheTieBreaker = blah
and now finally:
is shouldWeRunTheTieBreaker == true { tiebreaker() }
}
and then have your tiebreaker() function.
What you're really looking for is a state machine, but don't worry about that for now.
The general "programming trick" you're looking for here is that you must do these things:
always do your processing
then, only afterwards,
in all cases, check IF you need to run the tiebreaker
run it if needed
That's the pattern.
Unfortunately, I don't have the rating to upvote.
I managed to resolve the issue. Instead of a function, I created a boolean for tiebreaker and it looks something like:
if (p1 = 100 || p2 == 100)
tiebreak = true;
if (p1 == 100 && tiebreaker){
p1 == OK;
tiebreaker = false;
} else //same thing for p2
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.
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
So I really have no clue why this isn't wokring - basic stuff I did hundred times before:
I want to disable the button 'loadGame' by doing the following if the boolean is false:
if(saveExists == false){
loadGame.setEnabled(false);
}else{
loadGame.setEnabled(true);
}
saveExists is a boolean taken from a sharedPreferences object which is by default false (works, because I already checked saveExists in an output line).
Basically no matter what cases I create with if/elseif/else the button doesn't seem to get disabled at any point - did I really miss something big?
Okay so here's some code concerning the SharedPreference:
SharedPreferences settings;
SharedPreferences.Editor preferenceEditor;
...
In the onCreate of the class where I want to disable the button:
Resource.settings = getSharedPreferences(Resource.PREFERENCE_AUDIO, MODE_PRIVATE);
Resource.preferenceEditor = Resource.settings.edit();
saveExists = Resource.settings.getBoolean("settings", false);
Log.d(TAG, "saveExists="+saveExists);
and finally, the part to disable the Button:
loadGame = (ImageButton) findViewById(R.id.loadButton);
loadGame.setEnabled(saveExists);
loadGame.setOnClickListener(new OnClickListener() {...}
Oh btw we're talking about a ImageButton here
SOLUTION: You won't see this coming
God I hate to break it to you but that was clearly my fault. My projectpartner toggled the buttons invisible/visible as part of the AsyncTask and it's executed after I'm doing what I tried here all the time - yup shame on me I guess :x
It's very hard to determine the problem without more information. If the is/elseif/else doesn't seem to be working, you can try modifying your code to this to see what's going on:
if(saveExists == false){
Log.v("TEST", "saveExists is false");
}else{
Log.v("TEST", "saveExists is true");
}
If that is working then the problem seems to be with disabling the button. Does execution this line without the if/else work?
loadGame.setEnabled(false);
EDIT
From your update, I see you're using an ImageButton. For disabling an ImageButton, use setClickable(saveExists)
why don't use saveExist itself into the argument no need to used if/else
loadGame.setEnabled(saveExists);
if it is true then it is enabled otherwise not