pygtk vlc player does not play next track - pygtk

I'm writing a small custom player based on libvlc. I've used much of the code from https://github.com/hartror/python-libvlc-bindings/blob/master/examples/gtkvlc.py that plays a single track just like I need.
Now I want to swtich to another track after previous has finished. To do that I catch callback "EventType.MediaPlayerEndReached" and in callback handler I write code:
<------>def endCallback(self,event):
<------><------>fname = vlc_controller.GetNextTrack()['url']
<------><------>self.w.set_title(fname)
<------><------>self.vlc.player.set_mrl(fname)
<------><------>self.w.set_title('after set_mrl')
<------><------>self.vlc.player.play()
<------><------>self.w.set_title('after play')
Now when this code gets executed it stucks on self.vlc.player.set_mrl(fname) and does not go any further and as a result I see NO NEXT TRACK.
I've tried different variations of this code using (vlc.stop(), vlc.set_media instead of vlc.set_mrl) but nothing works

Finally....
I think the best choise is to make multi threaded application on python
2 Threads:
Main thread - gtk.loop and displaying video an some other thinks
Additional thread that makes media switching.
For some time I was afraid of multithreading but now I know that this was the best way to do this task

For those facing similar issue in C# (Xamarin), per VLC documentation, calling the VLC object from an event tied to the object may freeze the application. So they said to use the code below inside the trigger event.
ThreadPool.QueueUserWorkItem(_ => PlayNext());
An example would be calling the code above inside the EndReach event.
Where PlayNext() is your own custom method to handle the next action you want to execute.
I struggled with this for about a day before seeing that portion of the documentation.

Related

wxWidgets: is it possible to nest two different wxTimers?

I am writing an application that stays in the traybar and do some checks every some minutes.
When it performs this checks, I would like the traybar icon to be animated.
That is why I have a first wxTimer triggering checks. In its OnTimer call I tried to manage the second wxTimer to handle the animation.
The issue is that timers work in the mainloop, so the icon is not updated when the second timer updates the icon index.
Is there a way to overcome this problem?
Thank you!
Your description of the problem is unfortunately not clear at all but if you mean that you don't get timer events until you reenter the event loop, this is indeed true and, moreover, almost tautological -- you need to return to the event loop to get any events.
This is the reason why your event handlers should always execute quickly and return control to the main loop. And if they take too long, the usual solution is to use a background thread for the real work and just schedule it in your event handler, but not wait until it is done.
Basing on Ryan G's comment
It is possible to incorporate wx.Yield() into the main loop. This is usually used to temporarily release the global lock to allow the widgets to update.
It is also possible to create a separate thread to update the animation independently from the main thread.
Using wx.Yield() should be easier to implement.

CAsyncSocketEx + console application ?

I have console applicaiotn that currently uses CAsyncSocket.
I need to implement SSL so after some searching I found this project: http://www.codeproject.com/Articles/3915/CAsyncSslSocketLayer-SSL-layer-class-for-CAsyncSoc
For some reason same simple code that works fine on GUI code does not work in console app.
Has anyone exp. with CAsyncSslSocketLayer ?
Thanks.
CAsyncSocketEx uses a window as a sort of cheap thread to handle the event notifications that come from select(). Unfortunately, if you don't have a message loop, then the window which it creates will not receive these events.
http://support.microsoft.com/kb/90975
This article explains that a call to CreateWindow() needs to be called from a thread which has a message loop. And if you don't, then anything sent via PostMessage() won't get there.
I've recently started to tinker with this -- I want to remove the annoying hidden window and replace it with a normal thread. Their code relies on WSAAsyncSelect() in order to receive socket events... to a window. Yuk!
It's been a while since I had the same problem, but if I remember correctly, to use CAsyncSocket in a console app you need to add something like DECLARE_CONSOLEAPP (first two links shown below) to your console app. This should give your console a message pump to generate the socket notifications (OnReceive, etc.) GUI apps have these pumps but console apps don't, generally. The third (msdn) link below might also apply, it has more info and a different way.
If these still don't work, you should put breakpoints in your socket code and make sure your socket isn't instantiated in a thread or callback other than the main console app (the one that now has the message pump).
I think googling around for 'CAsyncSocket WinApp' or 'CAsyncSocket console app' would show more.
http://www.codeguru.com/cpp/misc/misc/consoleapps/article.php/c243/Console-app-using-MFC.htm
http://troels.knakkergaard.dk/code.htm
http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/a6f1b72a-21d8-4046-a3dc-d7d29ece2ef6

Pausing the Current function for some time iphone

Hi all im trying to pause a function so some time in the middle of execution because ill have to wait for the call back functions from GData api and get my data ready to put in that function i dont know how to do that. I am developing in Xcode 4.2 really need some help
You need to consider redesigning a little bit. What ever portion of code you expect to process after callback happens, let that code called by the callback. That way it will give you the guarantee that it always executes after the callback.
where you want to wait your functionality write this code [self performSelector:#selector(WaitForTwoSecond) withObject:nil afterDelay:2]; and implement - (void)WaitForTwoSecond { //write your code here } this method wait for two second and after that you cant access all data and put it in appropriate place .
we can say that this function is working like in background process

Updating UI Manually

Is there a way to update UI manually?
For example, I have a function which updates UI and execute some logic.
After the UI update, it will execute some logic that will take a long time and update of UI has to be wait until the execution of logic is finished.
Is there a way to update UI manually befor even the logic is even executed?
It seems that thread can be used in here.
But Is there a way to solve this by not using thread?
Also, using if thread can be used, what is the best practice?
Thanks!
Because the UI thread is the main thread of your app, it's generally not a good idea to process big operations on it because you froze your UI in the meantime (which is not user friendly).
The way you use thread depends on what you want to do, you can for example just use - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg or you can create your own thread and be more specific.
Don't forget to call - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait if you want to do some changes on the UI from other thread.
You'll find all you need about thread programming in this guide from iOS Reference Library.
Hope this helps !
Are you thinking about a simple progress bar? If that is the case, then you can use something using NSApp (see the section under Managing the Event Loop) and use runModalForWindow: and runModalSession: These will allow you to open a progress panel, report on status and allow a method to cancel the operation.
Because the operation is modal, other UI elements will be deactivated until the panel is dismissed.

How do I pause a function in c or objective-c on mac without using sleep()

Hi I would like to pause the execution of a function in an cocoa project. I dont want to use sleep() because the function needs to resume after user interaction. I also want to avoid doing this with multiple calls to sleep.
Thanks for your responses. Ok I started the code while waiting for some answers. I then realized that sleep or pause would not be usefull to me because it freeses my whole program. I think I might have to do some threading. Here is the situation:
I have a program that uses coreplot. I also use it to debug and develop algorithms so I do lots of plots while the data is being processed (ie in the midfle of the code but I need the flexibility to put it anywhaere so I cant separate my function). I was able to do this with NSRunAlertPanel but having a message box like that doesnt make it very presentable and I cant do much with the main window while an alert is open.
I hope I am not too confusing with my explanation but if I am ill try to one line it here:
I would like to interact with my cocoa interface while one of my functions is stopped in the middle of what it is doing.
Its sounds to me like you're looking for -NSRunLoop runUntilDate:
Apple's Docs: runUntilDate
This code will cause the execution within your method to pause but still let other events like timers and user input occur:
while ( functionShouldPause )
{
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
}
Switching functionShouldPause back to false will allow the rest of the method to execute.
It seems more like you are interested in reacting to user events rather than "pausing" the function. You would probably want to put the code that you want to execute into another function that is called as a result of the user's actions.
In C you can use the pause() function in <unistd.h>. This causes the calling program to suspend until it receives a signal, at which point the pause call will return and your program will continue (or call a signal handler; depending on what signal was received).
So it sounds like you want to break the function into two parts; the bit that happens before the sleep and the bit that happens afterward. Before going to sleep, register for a notification that calls the "after" code, and can be triggered by the UI (by an IBAction connected to whatever UI element). Now instead of calling sleep(), run the run loop for the period you want to go to sleep for, then after that has returned post the "after" notification. In the "after" code, remove the object as an observer for that notification. Now, whichever happens first - the time runs out or the user interrupts you - you get to run the "after" code.
Isn't there a clock or timer function? When your button is pressed start running a loop like timeTillAction = 10 and do a loop of timeTillAction = timeTillAction - 1 until it reaches 0 then run whatever code after the 10 seconds.
Sorry if this isn't well explained.