Home > APIs > AppServer API > Examples > Timeline and Transport Control > Create a Basic Playlist
Below is example C# and C++ code for creating a basic playlist. This playlist has two sections that each contain two events. See Playlists, Sections, and Events for an explanation on playlists.
A C# sample script can also be found on the C# Scripts Sample page.
[C#] // create a two-head player recorder bool isNewController = false; ITwoHeadPlayerRecorder player = (ITwoHeadPlayerRecorder) appServer.CreateController( "YourApplicationName", "C1", out isNewController); // set loop play mode to false player.LoopPlayMode = false; // enable list pauses player.SetChannelProperty("listpauses", "true"); // enable list repeats player.SetChannelProperty("listrepeats", "true"); // set current bin player.SetCurrentBin("V:", "default"); // generate a unique name for the playlist (i.e. playlist, playlist_0, etc.) string playlist = player.GenerateUniqueName ("playlist", "_"); // eject the play first to make sure we're clean player.Eject(); // generate a new clip name (which also loads it) player.New(playlist); // get the editor IEventEditor editor = (IEventEditor) player.GetEditor(); // insert the first section string section1 = editor.InsertSection(""); // set the starting timecode editor.SetStartingTimecode("01:00:00,00"); // insert several play events and get properties back string editID_A = editor.InsertPlayEvent(@"edl/cmf//local/V:/default/ClipA", section1, 0, ""); object[] array = (object[]) editor.GetEventProperty (editID_A, "name+startpos+duration"); // your code to do something with event properties string editID_B = editor.InsertPlayEvent(@"edl/cmf//local/V:/default/ClipB", section1, 0, ""); array = (object[]) editor.GetEventProperty (editID_B, "name+startpos+duration"); // your code to do something with event properties // insert another section string section2 = editor.InsertSection(""); // insert several more play events and get properties back string editID_C = editor.InsertPlayEvent(@"edl/cmf//local/V:/default/ClipC", section2, 0, ""); array = (object[]) editor.GetEventProperty (editID_C, "name+startpos+duration"); // your code to do something with event properties string editID_D = editor.InsertPlayEvent(@"edl/cmf//local/V:/default/ClipD", section2, 0, ""); array = (object[]) editor.GetEventProperty (editID_D, "name+startpos+duration"); // your code to do something with event properties // play the list for awhile player.Play(); Thread.Sleep(30000); player.Stop(); // delete events editor.DeleteEvent(editID_C); editor.DeleteEvent(editID_D); // delete section 2 editor.DeleteSection(section2); // note: you cannot delete all sections. Since this is a playlist // it will force you to keep at least one section in it. // editor.DeleteSection(section2); // this would error // eject the clip player.Eject(); // close the channel player.CloseChannel(); // cleanup editor.Detach();
[C++] short nIsNewController; ISimpleControllerPtr spController; _variant_t varChanNum(m_bstrChannel); // create the controller and cast it to different interfaces HRESULT hr = spAppServer->CreateController(_bstr_t("YourApplicationName"), _bstr_t("C1"), &nIsNewController, &spController); //printf("CreateController hresult = 0x%x\n", hr); ISimplePlayerRecorderPtr spPlayer = (ISimplePlayerRecorderPtr) spController; ITwoHeadPlayerRecorderPtr spTwoHeadPlayer = (ITwoHeadPlayerRecorderPtr) spController; // set loop play mode to false VARIANT_BOOL loopmode(FALSE); hr = spPlayer->put_LoopPlayMode(loopmode); // enable list pauses hr = spController->SetChannelProperty(_bstr_t("listpauses"), _variant_t("true")); // enable list repeats hr = spController->SetChannelProperty(_bstr_t("listrepeats"), _variant_t("true")); // set current bin hr = spController->SetCurrentBin(_bstr_t("V:"), _bstr_t("default")); // generate a unique name for the playlist (i.e. playlist, playlist_0, etc.) BSTR playlist; hr = spController->GenerateUniqueName (_bstr_t("playlist"), _bstr_t("_"), &playlist); // eject the play first to make sure we're clean hr = spPlayer->Eject(); // create the new playlist (which also loads it) hr = spPlayer->New(playlist); // get an editor and cast it to an event editor ISimpleEditorPtr spEditor; hr = spPlayer->GetEditor(&spEditor); IEventEditorPtr spEventEditor = (IEventEditorPtr) spEditor; // insert the first section BSTR section1; hr = spEventEditor->InsertSection(_bstr_t(""), §ion1); // set the default starting timecode (this is what AppCenter does). spEditor->SetStartingTimecode(_variant_t("01:00:00,00")); // insert several play events and get properties back BSTR editID_A; VARIANT varResult; hr = spEventEditor->InsertPlayEvent(_bstr_t("edl/cmf//local/V:/default/ClipA"), section1, 0, _bstr_t(""), &editID_A); hr = spEventEditor->GetEventProperty (editID_A, _bstr_t("name+startpos+duration"), &varResult); // your code to do something with event properties BSTR editID_B; hr = spEventEditor->InsertPlayEvent(_bstr_t("edl/cmf//local/V:/default/ClipB"), section1, 0, _bstr_t(""), &editID_B); hr = spEventEditor->GetEventProperty (editID_B, _bstr_t("name+startpos+duration"), &varResult); // your code to do something with event properties // insert another section BSTR section2; hr = spEventEditor->InsertSection(_bstr_t(""), §ion2); // insert several more play events and get properties back BSTR editID_C; hr = spEventEditor->InsertPlayEvent(_bstr_t("edl/cmf//local/V:/default/ClipA"), section1, 0, _bstr_t(""), &editID_C); hr = spEventEditor->GetEventProperty (editID_C, _bstr_t("name+startpos+duration"), &varResult); // your code to do something with event properties BSTR editID_D; hr = spEventEditor->InsertPlayEvent(_bstr_t("edl/cmf//local/V:/default/ClipB"), section1, 0, _bstr_t(""), &editID_D); hr = spEventEditor->GetEventProperty (editID_D, _bstr_t("name+startpos+duration"), &varResult); // your code to do something with event properties // play for awhile hr = spPlayer->Play(); Sleep(30000); // eject hr = spPlayer->Eject(); // close channel hr = spController->CloseChannel(); // cleanup hr = spEditor->Detach();