Example 2: Timeshifting
Table of contents
No headersThe purpose of this example is to demonstrate :
- how to connect to the TV-Server
- how to retrieve channel information from the TV database
- how to start timeshifting a channel
- how to stop timeshifting a channel
Copy the DLLs under ...\TvEngine3\TVLibrary\TVDatabase\references and ...\ProgramData\Team MediaPortal\MediaPortal\Gentle.config to your output directory.
The code can be found in the TvServer SVN under doc\examples\examples\example2
#region Copyright (C) 2005-2012 Team MediaPortal
// Copyright (C) 2005-2012 Team MediaPortal
// http://www.team-mediaportal.com
//
// MediaPortal is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// MediaPortal is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections;
using System.Text;
using TvControl; // include the tvserver remote control interfaces
using TvLibrary.Channels; // include tv-channel types
using TvDatabase; // include tv-server database
namespace Example2
{
/// <summary>
/// example which connects to the tvserver
/// and starts timeshifting then waits 5 seconds and then stops timeshifting.
/// </summary>
class Program
{
static void Main(string[] args)
{
try
{
//set the hostname of the tvserver
RemoteControl.HostName = "sirius";
//get the location of the database..
string connStr;
string provider;
IController controller = RemoteControl.Instance;
controller.GetDatabaseConnectionString(out connStr, out provider);
//set the connection string
Gentle.Framework.ProviderFactory.SetDefaultProviderConnectionString(connStr);
// Now get a list of all tv-channels
IList<Channel> channels = Channel.ListAll();
//lets take the first channel
Channel channel = (Channel)channels[0];
Console.WriteLine("timeshifting channel:{0}", channel.DisplayName);
//start timeshifting
IUser me = new User();
VirtualCard vcard;
TvResult result = controller.StartTimeShifting(ref me, channel.IdChannel, out vcard);
if (result != TvResult.Succeeded)
{
//failed to start timeshifting
Console.WriteLine("timeshifting failed:{0}", result);
}
else
{
Console.WriteLine("timeshifting succeeded");
Console.WriteLine(" rtsp url:{0}", vcard.RTSPUrl);
Console.WriteLine(" filename:{0}", vcard.TimeShiftFileName);
//sleep 5 secs
System.Threading.Thread.Sleep(5000);
//stop timeshifting
vcard.StopTimeShifting();
}
}catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
