NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 42 43 44 45 46 … 93 Next »
MultiThreaded stuff.

 
  • 0 Vote(s) - 0 Average
MultiThreaded stuff.
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#1
2007-06-23, 04:34 AM
Hi

Trying to make my music player a bit better. Loading playlists were a place where the UI would stop while a large playlist was loaded. So I'd like to make it load in background.

I've managed to make it start a new thread to load the playlist files inthe background ok. But the problem comes when trying to play them.

If I try to play a track while it loading, and call a PluginHelperFactory.AddAudioFileToQueue() both within the playlist class (that's currently loading - i.e. so in the new thread) or an event that fires when each track is loaded I get
Code:
Cross-thread operation not valid: Control 'HomeMenu' accessed from a thread other than the thread it was created on.

Any pointers to how I should be doing this?? I'm pretty new to multi-threading...
sub
Online

Administrator

NextPVR HQ, New Zealand
Posts: 106,807
Threads: 769
Joined: Nov 2003
#2
2007-06-23, 05:06 AM
This can be tricky. There are several of the PluginHelper APIs that can only be called on the main thread - primarily any that need to tell a music file to start playing. This is because this is a limitation of the Windows Media Player control. You would have got away with calling AddAudioFileToQueue() if a music file had already been playing (initiated from main thread).

In general I use background threads for doing long running activities (downloading youtube files etc), but only call the playback APIs from the main thread if I see semaphore/flag indicating the download is complete.
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#3
2007-06-23, 06:12 AM
I've managed to make it start playing a first track, and I'll just figure out a way of notifiying the rest of the program that the remainder of the tracks are ready.
sub
Online

Administrator

NextPVR HQ, New Zealand
Posts: 106,807
Threads: 769
Joined: Nov 2003
#4
2007-06-23, 06:44 AM
As long as it's already playing, you'd be safe to call the AddAudioFileToQueue() method in the background thread. Its probably the easiest way to achieve what you want.
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#5
2007-06-23, 06:47 AM
oh ok, something to try then. I'll let you know.

Have to see what other things I can push into a background thread.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  webapi and silly cross site scripting stuff reven 6 3,179 2014-01-20, 03:06 AM
Last Post: reven
  Windows Media Connect - Storing stuff on a Home Server psycik 3 2,759 2009-09-29, 03:47 AM
Last Post: mvallevand

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode