本文整理汇总了C#中IMediaItem.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IMediaItem.GetType方法的具体用法?C# IMediaItem.GetType怎么用?C# IMediaItem.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMediaItem
的用法示例。
在下文中一共展示了IMediaItem.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public bool Register(User user, IMediaItem m, long? timestamp = null)
{
// Begin building object
NowPlaying nowPlaying = new NowPlaying();
// Store user object
nowPlaying.User = user;
// Check if client sent a timestamp (if not, use current time)
if (timestamp == null)
{
timestamp = DateTime.UtcNow.ToUnixTime();
}
// Capture play time to set up automatic unregister on playback end
nowPlaying.StartTime = timestamp;
nowPlaying.EndTime = timestamp + Convert.ToInt32(m.Duration);
// Start a timer, set to elapse and unregister this song exactly when it should finish playback
nowPlaying.Timer = new Timer(Convert.ToInt32(m.Duration) * 1000);
nowPlaying.Timer.Elapsed += delegate { this.Unregister(user.UserName, user.CurrentSession.ClientName); };
nowPlaying.Timer.Start();
// Capture media item's type
Type mediaType = m.GetType();
// Unregister any items with matching user and client
this.Unregister(user.UserName, user.CurrentSession.ClientName);
// Handling for Song items
if (mediaType.IsAssignableFrom(typeof(Song)))
{
// Box IMediaItem to Song
Song s = (Song)m;
nowPlaying.MediaItem = s;
// Report now playing
playing.Add(nowPlaying);
logger.IfInfo(String.Format("{0}@{1} Now Playing: {2} - {3} - {4} [{5}]",
user.UserName,
user.CurrentSession.ClientName,
s.ArtistName,
s.AlbumName,
s.SongName,
Convert.ToInt32(s.Duration).ToTimeString()
));
}
// Handling for Video items
else if (mediaType.IsAssignableFrom(typeof(Video)))
{
// Box IMediaItem to Video
Video v = (Video)m;
nowPlaying.MediaItem = v;
// Report now playing
playing.Add(nowPlaying);
logger.IfInfo(String.Format("{0}@{1} Now Watching: {2} [{3}]",
user.UserName,
user.CurrentSession.ClientName,
v.FileName,
Convert.ToInt32(v.Duration).ToTimeString()
));
}
else
{
// Report unsupported media types
logger.IfInfo("Media type not supported, skipping now playing registration...");
}
return true;
}