private void SetDeviceSpecificData(BaseItem item, MediaSourceInfo mediaSource, DeviceProfile profile, AuthorizationInfo auth, long?maxBitrate, long startTimeTicks, string mediaSourceId, int?audioStreamIndex, int?subtitleStreamIndex, int?maxAudioChannels, string playSessionId, Guid userId, bool enableDirectPlay, bool forceDirectPlayRemoteMediaSource, bool enableDirectStream, bool enableTranscoding, bool allowVideoStreamCopy, bool allowAudioStreamCopy) { var streamBuilder = new StreamBuilder(_mediaEncoder, Logger); var options = new VideoOptions { MediaSources = new MediaSourceInfo[] { mediaSource }, Context = EncodingContext.Streaming, DeviceId = auth.DeviceId, ItemId = item.Id, Profile = profile, MaxAudioChannels = maxAudioChannels }; if (string.Equals(mediaSourceId, mediaSource.Id, StringComparison.OrdinalIgnoreCase)) { options.MediaSourceId = mediaSourceId; options.AudioStreamIndex = audioStreamIndex; options.SubtitleStreamIndex = subtitleStreamIndex; } var user = _userManager.GetUserById(userId); if (!enableDirectPlay) { mediaSource.SupportsDirectPlay = false; } if (!enableDirectStream) { mediaSource.SupportsDirectStream = false; } if (!enableTranscoding) { mediaSource.SupportsTranscoding = false; } if (item is Audio) { Logger.LogInformation("User policy for {0}. EnableAudioPlaybackTranscoding: {1}", user.Name, user.Policy.EnableAudioPlaybackTranscoding); } else { Logger.LogInformation("User policy for {0}. EnablePlaybackRemuxing: {1} EnableVideoPlaybackTranscoding: {2} EnableAudioPlaybackTranscoding: {3}", user.Name, user.Policy.EnablePlaybackRemuxing, user.Policy.EnableVideoPlaybackTranscoding, user.Policy.EnableAudioPlaybackTranscoding); } if (mediaSource.SupportsDirectPlay) { if (mediaSource.IsRemote && forceDirectPlayRemoteMediaSource) { } else { var supportsDirectStream = mediaSource.SupportsDirectStream; // Dummy this up to fool StreamBuilder mediaSource.SupportsDirectStream = true; options.MaxBitrate = maxBitrate; if (item is Audio) { if (!user.Policy.EnableAudioPlaybackTranscoding) { options.ForceDirectPlay = true; } } else if (item is Video) { if (!user.Policy.EnableAudioPlaybackTranscoding && !user.Policy.EnableVideoPlaybackTranscoding && !user.Policy.EnablePlaybackRemuxing) { options.ForceDirectPlay = true; } } // The MediaSource supports direct stream, now test to see if the client supports it var streamInfo = string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ? streamBuilder.BuildAudioItem(options) : streamBuilder.BuildVideoItem(options); if (streamInfo == null || !streamInfo.IsDirectStream) { mediaSource.SupportsDirectPlay = false; } // Set this back to what it was mediaSource.SupportsDirectStream = supportsDirectStream; if (streamInfo != null) { SetDeviceSpecificSubtitleInfo(streamInfo, mediaSource, auth.Token); } } } if (mediaSource.SupportsDirectStream) { options.MaxBitrate = GetMaxBitrate(maxBitrate, user); if (item is Audio) { if (!user.Policy.EnableAudioPlaybackTranscoding) { options.ForceDirectStream = true; } } else if (item is Video) { if (!user.Policy.EnableAudioPlaybackTranscoding && !user.Policy.EnableVideoPlaybackTranscoding && !user.Policy.EnablePlaybackRemuxing) { options.ForceDirectStream = true; } } // The MediaSource supports direct stream, now test to see if the client supports it var streamInfo = string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ? streamBuilder.BuildAudioItem(options) : streamBuilder.BuildVideoItem(options); if (streamInfo == null || !streamInfo.IsDirectStream) { mediaSource.SupportsDirectStream = false; } if (streamInfo != null) { SetDeviceSpecificSubtitleInfo(streamInfo, mediaSource, auth.Token); } } if (mediaSource.SupportsTranscoding) { options.MaxBitrate = GetMaxBitrate(maxBitrate, user); // The MediaSource supports direct stream, now test to see if the client supports it var streamInfo = string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ? streamBuilder.BuildAudioItem(options) : streamBuilder.BuildVideoItem(options); if (streamInfo != null) { streamInfo.PlaySessionId = playSessionId; if (streamInfo.PlayMethod == PlayMethod.Transcode) { streamInfo.StartPositionTicks = startTimeTicks; mediaSource.TranscodingUrl = streamInfo.ToUrl("-", auth.Token).TrimStart('-'); if (!allowVideoStreamCopy) { mediaSource.TranscodingUrl += "&allowVideoStreamCopy=false"; } if (!allowAudioStreamCopy) { mediaSource.TranscodingUrl += "&allowAudioStreamCopy=false"; } mediaSource.TranscodingContainer = streamInfo.Container; mediaSource.TranscodingSubProtocol = streamInfo.SubProtocol; } // Do this after the above so that StartPositionTicks is set SetDeviceSpecificSubtitleInfo(streamInfo, mediaSource, auth.Token); } } }
///<exclude/> public bool Equals(DeviceProfile other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other._DeviceType == (_DeviceType) && other._Manufacturer == (_Manufacturer) && other._Model == (_Model) && other._Version == (_Version) && other._Properties.SequenceEqual(_Properties); }
internal void SerializeToXml(DeviceProfile profile, string path) { _xmlSerializer.SerializeToFile(profile, path); }
private void NormalizeMediaSourceContainer(MediaSourceInfo mediaSource, DeviceProfile profile, DlnaProfileType type) { mediaSource.Container = StreamBuilder.NormalizeMediaSourceFormatIntoSingleContainer(mediaSource.Container, mediaSource.Path, profile, type); }
private void SetDeviceSpecificData(BaseItem item, MediaSourceInfo mediaSource, DeviceProfile profile, AuthorizationInfo auth, int?maxBitrate, long startTimeTicks, string mediaSourceId, int?audioStreamIndex, int?subtitleStreamIndex, string playSessionId) { var streamBuilder = new StreamBuilder(Logger); var options = new VideoOptions { MediaSources = new List <MediaSourceInfo> { mediaSource }, Context = EncodingContext.Streaming, DeviceId = auth.DeviceId, ItemId = item.Id.ToString("N"), Profile = profile }; if (string.Equals(mediaSourceId, mediaSource.Id, StringComparison.OrdinalIgnoreCase)) { options.MediaSourceId = mediaSourceId; options.AudioStreamIndex = audioStreamIndex; options.SubtitleStreamIndex = subtitleStreamIndex; } if (mediaSource.SupportsDirectPlay) { var supportsDirectStream = mediaSource.SupportsDirectStream; // Dummy this up to fool StreamBuilder mediaSource.SupportsDirectStream = true; options.MaxBitrate = maxBitrate; // The MediaSource supports direct stream, now test to see if the client supports it var streamInfo = string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ? streamBuilder.BuildAudioItem(options) : streamBuilder.BuildVideoItem(options); if (streamInfo == null || !streamInfo.IsDirectStream) { mediaSource.SupportsDirectPlay = false; } // Set this back to what it was mediaSource.SupportsDirectStream = supportsDirectStream; if (streamInfo != null) { SetDeviceSpecificSubtitleInfo(streamInfo, mediaSource, auth.Token); } } if (mediaSource.SupportsDirectStream) { options.MaxBitrate = GetMaxBitrate(maxBitrate); // The MediaSource supports direct stream, now test to see if the client supports it var streamInfo = string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ? streamBuilder.BuildAudioItem(options) : streamBuilder.BuildVideoItem(options); if (streamInfo == null || !streamInfo.IsDirectStream) { mediaSource.SupportsDirectStream = false; } if (streamInfo != null) { SetDeviceSpecificSubtitleInfo(streamInfo, mediaSource, auth.Token); } } if (mediaSource.SupportsTranscoding) { options.MaxBitrate = GetMaxBitrate(maxBitrate); // The MediaSource supports direct stream, now test to see if the client supports it var streamInfo = string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ? streamBuilder.BuildAudioItem(options) : streamBuilder.BuildVideoItem(options); if (streamInfo != null) { streamInfo.PlaySessionId = playSessionId; SetDeviceSpecificSubtitleInfo(streamInfo, mediaSource, auth.Token); } if (streamInfo != null && streamInfo.PlayMethod == PlayMethod.Transcode) { streamInfo.StartPositionTicks = startTimeTicks; mediaSource.TranscodingUrl = streamInfo.ToUrl("-", auth.Token).TrimStart('-'); mediaSource.TranscodingContainer = streamInfo.Container; mediaSource.TranscodingSubProtocol = streamInfo.SubProtocol; } } }
private PlaylistItem GetPlaylistItem(BaseItem item, MediaSourceInfo[] mediaSources, DeviceProfile profile, string deviceId, string mediaSourceId, int?audioStreamIndex, int?subtitleStreamIndex) { if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) { return(new PlaylistItem { StreamInfo = new StreamBuilder(_mediaEncoder, _logger).BuildVideoItem(new VideoOptions { ItemId = item.Id, MediaSources = mediaSources, Profile = profile, DeviceId = deviceId, MaxBitrate = profile.MaxStreamingBitrate, MediaSourceId = mediaSourceId, AudioStreamIndex = audioStreamIndex, SubtitleStreamIndex = subtitleStreamIndex }), Profile = profile }); } if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase)) { return(new PlaylistItem { StreamInfo = new StreamBuilder(_mediaEncoder, _logger).BuildAudioItem(new AudioOptions { ItemId = item.Id, MediaSources = mediaSources, Profile = profile, DeviceId = deviceId, MaxBitrate = profile.MaxStreamingBitrate, MediaSourceId = mediaSourceId }), Profile = profile }); } if (string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase)) { return(PlaylistItemFactory.Create((Photo)item, profile)); } throw new ArgumentException("Unrecognized item type."); }
private static DeviceProfile GetWindowsPhoneProfileNonS4(bool isHls = false) { var profile = new DeviceProfile(); #region Transcoding Profiles var transcodingProfiles = new List <TranscodingProfile> { new TranscodingProfile { Container = "mp3", AudioCodec = "mp3", Type = DlnaProfileType.Audio, Context = EncodingContext.Streaming }, new TranscodingProfile { Container = "mp4", VideoCodec = "h264", AudioCodec = "aac", Type = DlnaProfileType.Video, Context = EncodingContext.Static }, new TranscodingProfile { Container = "mp3", AudioCodec = "mp3", Type = DlnaProfileType.Audio, Context = EncodingContext.Static }, new TranscodingProfile { Container = "jpeg,png,gif,bmp", Type = DlnaProfileType.Photo, Context = EncodingContext.Static } }; if (isHls) { transcodingProfiles.Add(new TranscodingProfile { Protocol = "hls", Container = "ts", VideoCodec = "h264", AudioCodec = "aac", Type = DlnaProfileType.Video, Context = EncodingContext.Streaming }); } transcodingProfiles.Add(new TranscodingProfile { Container = "mp4", VideoCodec = "h264", AudioCodec = "aac", Type = DlnaProfileType.Video, Context = EncodingContext.Streaming }); profile.TranscodingProfiles = transcodingProfiles.ToArray(); #endregion #region Direct play Profiles profile.DirectPlayProfiles = new[] { new DirectPlayProfile { Container = "3gp,mp4,mov,m4v", VideoCodec = "h264", AudioCodec = "aac,mp3", Type = DlnaProfileType.Video }, new DirectPlayProfile { Container = "mp4,m4v,avi,3gp", VideoCodec = "mpeg4,msmpeg4", AudioCodec = "aac,mp3", Type = DlnaProfileType.Video }, new DirectPlayProfile { Container = "wmv", VideoCodec = "vc1", AudioCodec = "aac,mp3", Type = DlnaProfileType.Video }, new DirectPlayProfile { Container = "asf", VideoCodec = "wmv2,wmv3,vc1", AudioCodec = "wmav2,wmapro,wmavoice", Type = DlnaProfileType.Video }, new DirectPlayProfile { Container = "asf", AudioCodec = "wmav2,wmapro,wmavoice", Type = DlnaProfileType.Audio }, new DirectPlayProfile { Container = "wma", AudioCodec = "wmav2,wmapro,wmavoice", Type = DlnaProfileType.Audio }, new DirectPlayProfile { Container = "mp3,mp4,aac,wma", Type = DlnaProfileType.Audio }, new DirectPlayProfile { Container = "jpeg,png,gif,bmp", Type = DlnaProfileType.Photo } }; #endregion #region Codec profiles profile.CodecProfiles = new[] { new CodecProfile { Type = CodecType.Video, Codec = "h264", Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.Width, Value = "1280" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.Height, Value = "720" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoBitrate, Value = "10000000", IsRequired = false }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoFramerate, Value = "30", IsRequired = false }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoLevel, Value = "31" }, new ProfileCondition(ProfileConditionType.EqualsAny, ProfileConditionValue.VideoProfile, "high|main|baseline|constrained baseline"), new ProfileCondition { Condition = ProfileConditionType.NotEquals, Property = ProfileConditionValue.IsAnamorphic, Value = "true" } } }, new CodecProfile { Type = CodecType.Video, Codec = "mpeg4,msmpeg4,wmv2,wmv3,vc1", Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.Width, Value = "800" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.Height, Value = "600" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoBitrate, Value = "2000000", IsRequired = false }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoFramerate, Value = "30", IsRequired = false }, new ProfileCondition { Condition = ProfileConditionType.NotEquals, Property = ProfileConditionValue.IsAnamorphic, Value = "true" } } }, new CodecProfile { Type = CodecType.VideoAudio, Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioBitrate, Value = "320000" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioChannels, Value = "2" } } }, new CodecProfile { Container = "mp3", Type = CodecType.Audio, Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioBitrate, Value = "320000" } } }, new CodecProfile { Container = "aac", Type = CodecType.Audio, Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioBitrate, Value = "320000" } } }, new CodecProfile { Container = "wma", Type = CodecType.Audio, Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioBitrate, Value = "256000" } } }, new CodecProfile { Container = "wma", Codec = "wmav2", Type = CodecType.Audio, Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioBitrate, Value = "256000" } } }, new CodecProfile { Container = "wma", Codec = "wmapro", Type = CodecType.Audio, Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioBitrate, Value = "256000" } } }, }; #endregion profile.MaxStreamingBitrate = 20000000; profile.MaxStaticBitrate = 20000000; return(profile); }
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, DeviceProfile profile, bool enableConversion, IProgress <double> progress, CancellationToken cancellationToken) { var options = _syncManager.GetAudioOptions(jobItem); options.DeviceId = jobItem.TargetId; options.Context = EncodingContext.Static; options.Profile = profile; options.ItemId = item.Id.ToString("N"); options.MediaSources = item.GetMediaSources(false, user).ToList(); var streamInfo = new StreamBuilder().BuildAudioItem(options); var mediaSource = streamInfo.MediaSource; jobItem.MediaSourceId = streamInfo.MediaSourceId; jobItem.TemporaryPath = GetTemporaryPath(jobItem); if (streamInfo.PlayMethod == PlayMethod.Transcode && job.Quality != SyncQuality.Original) { if (!enableConversion) { return; } jobItem.Status = SyncJobItemStatus.Converting; await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await UpdateJobStatus(job).ConfigureAwait(false); try { var lastJobUpdate = DateTime.MinValue; var innerProgress = new ActionableProgress <double>(); innerProgress.RegisterAction(async pct => { progress.Report(pct); if ((DateTime.UtcNow - lastJobUpdate).TotalSeconds >= DatabaseProgressUpdateIntervalSeconds) { jobItem.Progress = pct / 2; await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await UpdateJobStatus(job).ConfigureAwait(false); } }); jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, profile) { OutputDirectory = jobItem.TemporaryPath }, innerProgress, cancellationToken); } catch (OperationCanceledException) { jobItem.Status = SyncJobItemStatus.Queued; jobItem.Progress = 0; } catch (Exception ex) { jobItem.Status = SyncJobItemStatus.Failed; _logger.ErrorException("Error during sync transcoding", ex); } if (jobItem.Status == SyncJobItemStatus.Failed || jobItem.Status == SyncJobItemStatus.Queued) { await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); return; } jobItem.MediaSource = await GetEncodedMediaSource(jobItem.OutputPath, user, false).ConfigureAwait(false); } else { if (mediaSource.Protocol == MediaProtocol.File) { jobItem.OutputPath = mediaSource.Path; } else if (mediaSource.Protocol == MediaProtocol.Http) { jobItem.OutputPath = await DownloadFile(jobItem, mediaSource, cancellationToken).ConfigureAwait(false); } else { throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); } jobItem.MediaSource = mediaSource; } jobItem.Progress = 50; jobItem.Status = SyncJobItemStatus.ReadyToTransfer; await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); }
private async Task Sync(SyncJobItem jobItem, SyncJob job, Video item, User user, DeviceProfile profile, bool enableConversion, IProgress <double> progress, CancellationToken cancellationToken) { var options = _syncManager.GetVideoOptions(jobItem, job); options.DeviceId = jobItem.TargetId; options.Context = EncodingContext.Static; options.Profile = profile; options.ItemId = item.Id.ToString("N"); options.MediaSources = item.GetMediaSources(false, user).ToList(); var streamInfo = new StreamBuilder().BuildVideoItem(options); var mediaSource = streamInfo.MediaSource; // No sense creating external subs if we're already burning one into the video var externalSubs = streamInfo.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode ? new List <SubtitleStreamInfo>() : streamInfo.GetExternalSubtitles(false); // Mark as requiring conversion if transcoding the video, or if any subtitles need to be extracted var requiresVideoTranscoding = streamInfo.PlayMethod == PlayMethod.Transcode && job.Quality != SyncQuality.Original; var requiresConversion = requiresVideoTranscoding || externalSubs.Any(i => RequiresExtraction(i, mediaSource)); if (requiresConversion && !enableConversion) { return; } jobItem.MediaSourceId = streamInfo.MediaSourceId; jobItem.TemporaryPath = GetTemporaryPath(jobItem); if (requiresConversion) { jobItem.Status = SyncJobItemStatus.Converting; } if (requiresVideoTranscoding) { // Save the job item now since conversion could take a while await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await UpdateJobStatus(job).ConfigureAwait(false); try { var lastJobUpdate = DateTime.MinValue; var innerProgress = new ActionableProgress <double>(); innerProgress.RegisterAction(async pct => { progress.Report(pct); if ((DateTime.UtcNow - lastJobUpdate).TotalSeconds >= DatabaseProgressUpdateIntervalSeconds) { jobItem.Progress = pct / 2; await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await UpdateJobStatus(job).ConfigureAwait(false); } }); jobItem.OutputPath = await _mediaEncoder.EncodeVideo(new EncodingJobOptions(streamInfo, profile) { OutputDirectory = jobItem.TemporaryPath }, innerProgress, cancellationToken); } catch (OperationCanceledException) { jobItem.Status = SyncJobItemStatus.Queued; jobItem.Progress = 0; } catch (Exception ex) { jobItem.Status = SyncJobItemStatus.Failed; _logger.ErrorException("Error during sync transcoding", ex); } if (jobItem.Status == SyncJobItemStatus.Failed || jobItem.Status == SyncJobItemStatus.Queued) { await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); return; } jobItem.MediaSource = await GetEncodedMediaSource(jobItem.OutputPath, user, true).ConfigureAwait(false); } else { if (mediaSource.Protocol == MediaProtocol.File) { jobItem.OutputPath = mediaSource.Path; } else if (mediaSource.Protocol == MediaProtocol.Http) { jobItem.OutputPath = await DownloadFile(jobItem, mediaSource, cancellationToken).ConfigureAwait(false); } else { throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); } jobItem.MediaSource = mediaSource; } if (externalSubs.Count > 0) { // Save the job item now since conversion could take a while await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await ConvertSubtitles(jobItem, externalSubs, streamInfo, cancellationToken).ConfigureAwait(false); } jobItem.Progress = 50; jobItem.Status = SyncJobItemStatus.ReadyToTransfer; await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); }
private PlaylistItem GetPlaylistItem(BaseItem item, List <MediaSourceInfo> mediaSources, DeviceProfile profile, string deviceId) { var video = item as Video; if (video != null) { return(new PlaylistItem { StreamInfo = new StreamBuilder().BuildVideoItem(new VideoOptions { ItemId = item.Id.ToString("N"), MediaSources = mediaSources, Profile = profile, DeviceId = deviceId }), Profile = profile }); } var audio = item as Audio; if (audio != null) { return(new PlaylistItem { StreamInfo = new StreamBuilder().BuildAudioItem(new AudioOptions { ItemId = item.Id.ToString("N"), MediaSources = mediaSources, Profile = profile, DeviceId = deviceId }), Profile = profile }); } var photo = item as Photo; if (photo != null) { return(new PlaylistItemFactory().Create(photo, profile)); } throw new ArgumentException("Unrecognized item type."); }
static void Main(string[] args) { // Set the persistors's path and password. // Information can be found at '../../../../sample-data/peristors/README.md', // or 'github-tutorials/sample-data/peristors/README.md'. // // The persistor directory path is correct because the Visual Studio solution // executes from 'github-tutorials/csharp/sdk-basics/profiles/Profiles/bin/x64/Debug'. String persistorPath = "../../../../../../../sample-data/persistors/sample-persistor.pw"; String persistorPassword = "******"; // Create a blank agent. Agent agent = new Agent(); // Create a password persistor and intialize agent. try { DeviceProfilePersistorPassword persistor = new DeviceProfilePersistorPassword(); persistor.FilePath = persistorPath; persistor.Password = persistorPassword; agent.SetMetadata(Agent.MetaApplicationName, "Ionic Profiles Tutorial"); agent.SetMetadata(Agent.MetaApplicationVersion, "1.0.0"); agent.Initialize(persistor); } catch (SdkException sdkExp) { Console.WriteLine("Agent initialization error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Get the profiles and check if the are any. List <DeviceProfile> profiles = agent.AllProfiles; if (!agent.HasAnyProfiles) { Console.WriteLine("No profiles for password persistor."); WaitForInput(); return; } // Display profile information. Console.WriteLine("ALL PROFILES:"); foreach (DeviceProfile profile in profiles) { Console.WriteLine("-----"); Console.WriteLine("ID : " + profile.DeviceId); Console.WriteLine("Name : " + profile.Name); Console.WriteLine("Keyspace : " + profile.KeySpace); Console.WriteLine("API URL : " + profile.Server); } // Verify an active profile exists. if (!agent.HasActiveProfile) { Console.WriteLine("No profile is set as active."); WaitForInput(); Environment.Exit(1); } // Display the active profile device ID. DeviceProfile activeProfilesile = agent.ActiveProfile; Console.WriteLine("\nACTIVE PROFILE: " + activeProfilesile.DeviceId); // Change the active profile. String newProfilesileId = "EfGh.1.54sdf8-sdfj-5802-sd80-248vwqucv9s73"; Console.WriteLine("\nSETTING NEW ACTIVE PROFILE: " + newProfilesileId); bool success = agent.SetActiveProfileById(newProfilesileId); if (!success) { Console.WriteLine("Failed to set active profile to: " + newProfilesileId); WaitForInput(); Environment.Exit(1); } // Display the active device ID. DeviceProfile newActiveProfilesile = agent.ActiveProfile; Console.WriteLine("\nNEW ACTIVE PROFILE: " + newActiveProfilesile.DeviceId); WaitForInput(); }