INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Another programming question  (Read 2330 times)

petrossa

  • World Citizen
  • ***
  • Posts: 127
Another programming question
« on: February 26, 2011, 01:07:08 am »

this code:
   case LOOP_THE_LIST:
     Playback->Stop();
             int index=PlayLists->GetNumberPlaylists();
     if (LoopList>=index) LoopList=0;
     for (int i=LoopList;j<index;i++)
     {
      NewPlayList=PlayLists->GetPlaylist(i);
      if (!NewPlayList) continue;
      t=NewPlayList->Name;
      if (t.Pos("Choral") || t.Pos("Classic") || t.Pos("Electronic")
         || t.Pos("Jazz") || t.Pos("Keyrouz") || t.Pos("Piano")
            || t.Pos("Trance") || t.Pos("Violin") || t.Pos("Vocal"))
      {
      Playlist->RemoveAllFiles();
      Fileslist=NewPlayList->GetFiles();
      if (!Fileslist) continue;
                      Fileslist->Play(0);
      LoopList=i+1;
      break;
      }

will crash MC16 immediately as well as the program itself.

Leaving out:
Playlist->RemoveAllFiles();

and it runs without problems.

My question:

a) Is this the way to change the Playing Now list to another Playlist
b) Why isn't it necessary to empty the Playing Now?

This is just a tryout, i would hate to run into issues due to this when i fully develop it. Any input will accepted graciously and the commenter will heaped with praise, may his path be strewn with rosepetals.
Logged

cncb

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2918
Re: Another programming question
« Reply #1 on: February 26, 2011, 09:53:57 pm »

In the piece of code "Playlist" is undefined so what is it?  I think Files.Play() might always replace what is playing and you would have to add files individually to Playing Now ("CurrentPlaylist") to not replace them.
Logged
-Craig    MO 4Media remote and player:  Android/TV/Auto | iOS | Windows 10/UWP

petrossa

  • World Citizen
  • ***
  • Posts: 127
Re: Another programming question
« Reply #2 on: February 27, 2011, 05:12:30 am »

Thank you for your response. Playlist is defined elsewhere:   Playlist=MCAutomation->GetCurPlaylist();

So if i understand correctly, you don't need to empty Playing now first to change to another playlist? I assumed it would just add the list to Playing Now.

If i add the files it takes several minutes to populate Playing Now with another  large playlist.

All i want to do is set the current playlist to "other" playlist. Weird there is no function or property for that. Also the documentation isn't very clear on this point.

(rose petals distributed)


Logged

cncb

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2918
Re: Another programming question
« Reply #3 on: February 27, 2011, 10:05:07 am »

Playing Now is always the current playlist that you are just adding and removing files from (there is no concept of playing/switching playlists).  I would recommend just adding files as necessary to Now Playing instead of using Files.Play() so you have complete control over what is happening.  Taking minutes to add files to Playing Now is not normal so something else is going on.

As to the crash: Any chance that "Playlist" is or becomes null before you are trying to remove all the files.
Logged
-Craig    MO 4Media remote and player:  Android/TV/Auto | iOS | Windows 10/UWP

petrossa

  • World Citizen
  • ***
  • Posts: 127
Re: Another programming question
« Reply #4 on: February 27, 2011, 12:04:01 pm »

tnx cnbc

By adding files you mean:
pseudocode

MJFileAutomation file=MJFilesAutomation::GetFile(number nFile)

MJCurPlaylistAutomation::AddFileByKey(MJFileAutomation::(file)GetKey(),position) ?

So you add the files by looking up their keys in the playlist and add the outcome to the current playlist if i understand it well.
Do you have to keep track of the position yourself or do you just give position number 0 so it'll add on top.

The problem with that is in the end the current playlist will be the entire library.......

The docs are a bit dense. Apparently they assume knowledge about the working of MC which i wouldn't know were to find.

Granted my errorchecking is minimal, but hey it's a tryout.

Playlist is a public in the class, it is used by
void __fastcall TMediaCenter::MCAutomationFireMJEvent(TObject *Sender, BSTR bstrType,
        BSTR bstrParam1, BSTR bstrParam2)
{
  UnicodeString trk;
  trk=bstrParam1;
  if (trk.Pos("TRACK") || trk.Pos("STATE")) {

   MJPlaybackStates states=Playback->State;
  PlayFile = Playlist->GetFile(Playlist->Position);
........

to display tracks. And that functions fine as long as i don't do the 'skip playlist'.
Also in the debugger Playlist is the same address as on startup.

So it's not a null pointer.

TO MC DEVELOPERS:

Please add Get/SetPlaylist to MJCurPlaylistAutomation........

Logged

cncb

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2918
Re: Another programming question
« Reply #5 on: February 27, 2011, 03:06:28 pm »

MJFileAutomation file=MJFilesAutomation::GetFile(number nFile)

MJCurPlaylistAutomation::AddFileByKey(MJFileAutomation::(file)GetKey(),position) ?

So you add the files by looking up their keys in the playlist and add the outcome to the current playlist if i understand it well.
Do you have to keep track of the position yourself or do you just give position number 0 so it'll add on top.

The problem with that is in the end the current playlist will be the entire library.......

Yes, that's what I meant.  You pass in -1 for position to add to the end.  Sorry, I'm not sure why RemoveAllFiles() isn't working for you.
Logged
-Craig    MO 4Media remote and player:  Android/TV/Auto | iOS | Windows 10/UWP

petrossa

  • World Citizen
  • ***
  • Posts: 127
Re: Another programming question
« Reply #6 on: February 28, 2011, 05:49:38 am »

tnx cnbc. I'll cobble together a tryout. Maybe the Removefiles only doesn't work in my context and will work normally when i do it your way. Maybe some loose pointer when you mix the two interfaces......

You've been a great help.  Much appreciated.
As promised:
Logged
Pages: [1]   Go Up