Im streaming video to my MIDLET. And while it is playing it, after 20 seconds (depends on a system setting) display on the phone goes to stand-by mode.
How can I prevent this so I can watch the video for 5 minutes for example without having to tap something to wakeup the display?
Yeeeey I figured it out!!! But its a little hack and not the actual "Dont-Go-To-Stand-By" functionality... nevertheless it works PERFECT!!!! =D
Ok so the idea is to define the timeout that the display needs to be woken up. I let the user define this in the "Settings" screen and I write that in RMS so I can read it later...
Next, I define the TimerTask that calls getDisplay().flashBacklight(100); method every time that the defined timeout expires. And, this works like a charm!!! =D
Here is the concept code. First on the VideoCanvas (screen for drawing video) I define the TimerTask:
private class WakeTask extends TimerTask
{
public void run()
{
display.flashBacklight(100);
}
}
Next in the VideoCanvas constructor I start the timer and pass it the timeout, for example 10 seconds... and thats it:
***
timer = new Timer();
timer.schedule(new WakeTask(), 0, 10000);
***
So if the display goes to stand by after 15 seconds, and the timer runs every 10 seconds, it will never go to stand by, and will stay waken until you stop the timer. And if it goes to stand by in 5 seconds, timer will wake it up every time it runs just like you do when you tap something on the phone to wake it up. =)))
Yaaaay... =)))
P.S. Tested on NOKIA N96.
Related
In my onDisbale() method in my Main class I have a loop which creates and starts new BukkitRunnables.
I'm getting a error in console: org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register task while disabled I need to somehow wait in my onDisable() method until all the BukkitRunnables I create in the loop are finished. How to do that?
My code looks like this:
#Override
public void onDisable() {
for (Player p : Bukkit.getOnlinePlayers()) {
new PlayerDataSaverRunnable().runTaskAsynchronously(this);
}
}
The onDisable method is the very last thing that gets called before your plugin is disabled and the server shuts down. So, as the error message says, you unfortunately can't schedule any new tasks in the onDisable function.
You mentioned in a comment that you were trying to write to a file in the plugins folder, and under normal circumstances you'd want to do that asynchronously. But, because onDisable only ever gets called when the server is shut down (or when the entire server is reloaded with /reload), it's perfectly fine to run code here that blocks the main thread and could potentially take a few seconds to run — in the case of a shutdown, by the time this method gets called, all the players will have already been kicked off the server, and so there's no "lag" to complain about. If your plugin is super advanced and has to save a bunch of stuff, I don't think any server owners would complain even if it took 10 or so seconds to disable.
Of course, you would have to be saving something crazy for it to take a whole 10 seconds to save. More than likely, most files will save in just a few milliseconds.
If you're really dead-set on disabling the plugin as fast as possible, you might consider having some async task that runs every 5 minutes or so and auto-saves the files. Then, in onDisable, you could only save files that changed since the auto-saver was last run. That's a good practice anyways, just incase the server crashes or the power goes out and the onDisable method doesn't get a chance to run. But, then again, I would still recommend that you save everything in the onDisable method (that's what I do for all of my plugins, as well), even if it will take a few seconds and block the main thread, just so you can be 100% sure that everything gets saved correctly.
I have built a game, and I am trying to display a countdown timer display to let the player know how much time he/she has to make a move.
def countdown(sec):
while sec:
minn, secc = divmod(sec, 60)
timeformat = '{:02d}:{:02d}'.format(minn, secc)
self.messages['text'] = timeformat
t.sleep(1)
sec -= 1
countdown(15)
The issue i run into is that this code freeze my application, where the user is unable to play until the countdown finishes. So I am trying to see how I could rewrite this code so that it does not affect the application. I think sleeps puts the game to sleep.
I have used Tkinter to build the interface of my app, and so the timer would need to be displayed on screen.
Thanks in advance.
I am making a program for a robot in a competition, and need to multithread.
When I make a second task (task two()) and try to start (startTask) it with a button press from a controller, it just executes the first statement of the task and only as long as the button is pressed, instead of the whole block. I've tried many things including putting a loop in the second task also, using a function instead of a task and sleeping for 200 milliseconds before, and after the startTask(two); function, but the same thing happens every time.
I can't post my program because I don't want other people to steal it, sorry.
What edits will make it run the whole block?
Any help would be appreciated.
Since this is Controller Mode, I'm assuming that you are setting the motors to stop when the corresponding button is not pressed.
if([...])
[...]
else
{
setMotorSpeed(motor10, 0);
}
This is the cause for the stopping of the motors when you release. All of the other methods that you tried had nothing to do with this, so they shouldn't have worked.
You need to put something like this:
int Motor10Speed;
[...]
if([...])
[...]
else
{
setMotorSpeed(motor10, Motor10Speed);
}
This will control an individual motor. Repeat this for all other motors being used.
After that is done, make the function look something like this:
task mini_function();
task main()
{
[...]
}
task mini_function()
{
Motor10Speed = 50;
sleep(1000);
Motor10Speed = 0;
}
Expand the above program so it matches your current function, while using the MotorSpeed variables as setMotorSpeed variables.
This should make you able to drive and run a function at the same time without them interrupting each other.
i`m using mediaElement to play background music in my app. And that works just fine.
Problem is when the user minimize the application. When the application resume there is no sound... I can play other sounds in my application but cant play that background music any more.
First i have this code to stop all background music at first time app open:
if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing)
{
Microsoft.Xna.Framework.Media.MediaPlayer.Pause();
FrameworkDispatcher.Update();
}
xaml code of that mediaElement
<MediaElement AutoPlay="True" Source="/Dodaci/pozadina.mp3" x:Name="muzika_pozadina" MediaEnded="pustiPonovo" Loaded="pustiPonovo" />
and the cs code
private void pustiPonovo(object sender, RoutedEventArgs e)
{
muzika_pozadina.Play();
}
sound is about 300kb size.
So, how can i resume that sound playing after the user resume the application?
When your App is put into Dormant State (when you hit Start buton for example), the MediaElement is stopped. Then after you return to your App (and it wasn't Tombstoned), the Page is not Initialized once again, which means that your MediaElement is not loaded once again, so your Music doesn't start once again.
It depends on your purpose and code how it can be returned. In very simple example when you don't need to remember music last position you can just set source of your MediaElement once again in OnNavigatedTo() event:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode == NavigationMode.Back)
muzika_pozadina.Source = new Uri("/Dodaci/pozadina.mp3", UriKind.RelativeOrAbsolute);
}
As you have set your MediaElement.AutoPlay to true - it should start automatically (because of that you probably also don't need your Loaded event pustiPonovo).
In more complicated cases you can take an advantage of Activation and Deactivation events of your App - returning to MediaElement from Dormant/Tombstoned case is well explained here in the article.
You should also read about Fast App Resume in case User decides to return to your App by Tile instead of Launchers-Choosers.
I haven't tried above code, but hopefully it will do the job.
I am trying to stop sound when user exits the application by pressing Hang up key in Series 60. But the application goes to background and the sound still plays.
I want to stop the sound when user clicks the Hang up key of the device. I called the stop() method of Player. I also called the stop() method at hidNotify();
{
Player p;
p.start();
p.stop();
}
The AMS calls (or should call) the destroyApp() method of the MIDlet when the user exits.
Try putting your p.stop() command in there. (And other clean-up code too).