private static ConfigData GetConfig() { ConfigData config = null; try { config = ConfigData.FromFile(ApplicationPaths.ConfigFile); } catch (Exception ex) { MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; DialogResult r = ev.Dialog(ex.Message + "\n" + Application.CurrentInstance.StringData("ConfigErrorDial"), Application.CurrentInstance.StringData("ConfigErrorCapDial"), DialogButtons.Yes | DialogButtons.No, 600, true); if (r == DialogResult.Yes) { config = new ConfigData(ApplicationPaths.ConfigFile); config.Save(); } else { Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication(); } } return(config); }
private bool Load() { try { this.data = ConfigData.FromFile(configFilePath); return(true); } catch (Exception ex) { MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; DialogResult r = ev.Dialog(ex.Message + "\nReset to default?", "Error in configuration file", DialogButtons.Yes | DialogButtons.No, 600, true); if (r == DialogResult.Yes) { if (!Directory.Exists(configFolderPath)) { Directory.CreateDirectory(configFolderPath); } this.data = new ConfigData(configFilePath); Save(); return(true); } else { return(false); } } }
public static bool CallPlayMedia(MediaCenterEnvironment mediaCenterEnvironment, Microsoft.MediaCenter.MediaType type, object media, bool queue) { string file = media.ToString(); Logger.ReportVerbose("Calling MediaCenterEnvironment.PlayMedia: " + file); return(mediaCenterEnvironment.PlayMedia(type, media, queue)); }
private bool CallPlayMediaUsingMediaCollection(MediaCenterEnvironment mediaCenterEnvironment, PlayableItem playable) { var coll = new MediaCollection(); // Create a MediaCollectionItem for each file to play if (playable.HasMediaItems) { PlaybackControllerHelper.PopulateMediaCollectionUsingMediaItems(this, coll, playable); } else { PlaybackControllerHelper.PopulateMediaCollectionUsingFiles(coll, playable); } // Set starting position if we're resuming if (playable.Resume) { var playstate = playable.MediaItems.First().PlaybackStatus; coll.CurrentIndex = playstate.PlaylistPosition; coll[playstate.PlaylistPosition].Start = new TimeSpan(playstate.PositionTicks); } CurrentMediaCollection = coll; bool success = PlaybackControllerHelper.CallPlayMedia(mediaCenterEnvironment, MediaType.MediaCollection, CurrentMediaCollection, false); if (!success) { CurrentMediaCollection = null; } return(success); }
/// <summary> /// Handles a change of Playstate by firing various events and post play processes /// </summary> private void HandleStoppedState(MediaCenterEnvironment env, MediaExperience exp, MediaTransport transport, PlaybackStateEventArgs e) { // Stop listening to the events env.PropertyChanged -= MediaCenterEnvironment_PropertyChanged; transport.PropertyChanged -= MediaTransport_PropertyChanged; // This will prevent us from getting in here twice after playback stops and calling post-play processes more than once. _HasStartedPlaying = false; _CurrentMediaCollection = null; var mediaType = exp.MediaType; // Check if internal wmc player is still playing, which could happen if the user launches live tv while playing something if (mediaType != Microsoft.MediaCenter.Extensibility.MediaType.TV) { Application.CurrentInstance.ShowNowPlaying = false; if (mediaType == Microsoft.MediaCenter.Extensibility.MediaType.Audio || mediaType == Microsoft.MediaCenter.Extensibility.MediaType.DVD) { PlaybackControllerHelper.ReturnToApplication(true); } } // Fire the OnFinished event for each item OnPlaybackFinished(e); }
public void UnlockPinEntered(bool pinCorrect) { MediaCenterEnvironment env = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; if (pinCorrect) { unlockLibrary(); env.Dialog(string.Format(Application.CurrentInstance.StringData("LibraryUnlockedDial"), this.unlockPeriod.ToString()), Application.CurrentInstance.StringData("LibraryUnlockedCapDial"), DialogButtons.Ok, 60, true); Application.CurrentInstance.Back(); //clear PIN screen if (Config.Instance.HideParentalDisAllowed) { if (Application.CurrentInstance.CurrentFolder != null && Application.CurrentInstance.CurrentFolder != Application.CurrentInstance.RootFolderModel) { Application.CurrentInstance.CurrentFolder.RefreshChildren(); } if (Application.CurrentInstance.RootFolderModel != null) { Application.CurrentInstance.RootFolderModel.RefreshChildren(); } } } else { env.Dialog(Application.CurrentInstance.StringData("IncorrectPINDial"), Application.CurrentInstance.StringData("LibraryUnlockedCapDial"), DialogButtons.Ok, 60, true); Application.CurrentInstance.Back(); //clear PIN screen Logger.ReportInfo("PIN Incorrect attempting to unlock library."); } }
/// <summary> /// Handles the MediaCenterEnvironment.PropertyChanged event /// </summary> protected void MediaCenterEnvironment_PropertyChanged(IPropertyObject sender, string property) { System.Diagnostics.Debug.Assert(Microsoft.MediaCenter.UI.Application.ApplicationThread == System.Threading.Thread.CurrentThread); Logger.ReportVerbose("MediaCenterEnvironment_PropertyChanged: " + property); MediaCenterEnvironment env = sender as MediaCenterEnvironment; MediaExperience exp = env.MediaExperience; if (exp != null) { MediaTransport transport = exp.Transport; if (transport != null) { transport.PropertyChanged -= MediaTransport_PropertyChanged; transport.PropertyChanged += MediaTransport_PropertyChanged; HandlePropertyChange(env, exp, transport, property); } else { Logger.ReportWarning("MediaCenterEnvironment_PropertyChanged: MediaTransport is null"); } } else { Logger.ReportWarning("MediaCenterEnvironment_PropertyChanged: MediaExperience is null"); } }
/// <summary> /// Handles the MediaCenterEnvironment.PropertyChanged event /// </summary> protected void MediaCenterEnvironment_PropertyChanged(IPropertyObject sender, string property) { Logger.ReportVerbose("MediaCenterEnvironment_PropertyChanged: " + property); MediaCenterEnvironment env = sender as MediaCenterEnvironment; MediaExperience exp = env.MediaExperience; if (exp != null) { MediaTransport transport = exp.Transport; if (transport != null) { transport.PropertyChanged -= MediaTransport_PropertyChanged; transport.PropertyChanged += MediaTransport_PropertyChanged; HandlePropertyChange(env, exp, transport, property); } else { Logger.ReportWarning("MediaCenterEnvironment_PropertyChanged: MediaTransport is null"); } } else { Logger.ReportWarning("MediaCenterEnvironment_PropertyChanged: MediaExperience is null"); } }
public void FinishInitialConfig() { MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; ev.Dialog("Initial configuration is complete, please restart Media Browser", "Restart", DialogButtons.Ok, 60, true); Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication(); }
public void PlaySecure(bool resume, bool queue) { try { if (this.IsPlayable || this.IsFolder) { if (PlayableItem.PlaybackController != Application.CurrentInstance.PlaybackController && PlayableItem.PlaybackController.RequiresExternalPage) { Application.CurrentInstance.OpenExternalPlaybackPage(this); } this.PlayableItem.QueueItem = queue; this.PlayableItem.PlaybackController.MetaDuration = this.BaseItem is Video && (this.baseItem as Video).RunningTime != null ? (this.baseItem as Video).RunningTime.Value : 0; this.PlayableItem.Play(this.PlayState, resume); if (!this.IsFolder && this.TopParent != null) { this.TopParent.AddNewlyWatched(this); //add to watched list if not a whole folder } } } catch (Exception e) { Logger.ReportException("Error playing item " + this.Name, e); MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; ev.Dialog(Application.CurrentInstance.StringData("ContentErrorDial") + "\n" + baseItem.Path, Application.CurrentInstance.StringData("ContentErrorCapDial"), DialogButtons.Ok, 60, true); } }
public void DeleteMediaItem(Item Item) { // Setup variables MediaCenterEnvironment mce = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; var msg = "Are you sure you wish to delete this media item?"; var caption = "Delete Confirmation"; // Present dialog DialogResult dr = mce.Dialog(msg, caption, DialogButtons.No | DialogButtons.Yes, 0, true); if (dr == DialogResult.Yes) { // Perform itemtype and configuration checks if (Item.ItemType == ItemType.Movie && (this.Config.Advanced_EnableDelete == true && this.Config.EnableAdvancedCmds == true) ) { Item Parent = Item.PhysicalParent; string path = Item.Path; try { if (Directory.Exists(path)) { Directory.Delete(path, true); } else if (File.Exists(path)) { File.Delete(path); } } catch (IOException) { mce.Dialog("The selected media item cannot be deleted due to an invalid path. Or you may not have sufficient access rights to perform this command.", "Delete Failed", DialogButtons.Ok, 0, true); } catch (Exception) { mce.Dialog("The selected media item cannot be deleted due to an unknown error.", "Delete Failed", DialogButtons.Ok, 0, true); } Back(); // Back to the Parent Item; This parent still contains old data. // These tricks are required in order to load the parent item with "fresh" data. if (session.BackPage()) // Double Back to the GrandParent because history still has old parent. { Navigate(Parent); // Navigate forward to Parent } else // No GrandParent to go back to. { Navigate(Parent); // Navigate to the parent again - this will refresh the objects session.BackPage(); // Now safe to go back to previous parent, and keep session history valid } } else { mce.Dialog("The selected media item cannot be deleted due to its Item-Type or you have not enabled this feature in the configuration file.", "Delete Failed", DialogButtons.Ok, 0, true); } } }
public static DialogResult DisplayDialog(string message, string caption, DialogButtons buttons, int timeout) { // We won't be able to take this during a page transition. This is good! // Conversly, no new pages can be navigated while this is present. lock (syncObj) { DialogResult result = MediaCenterEnvironment.Dialog(message, caption, buttons, timeout, true); return(result); } }
public static void WaitForStream(MediaCenterEnvironment mce) { int i = 0; while ((i++ < 15) && (mce.MediaExperience.Transport.PlayState != Microsoft.MediaCenter.PlayState.Playing)) { // settng the position only works once it is playing and on fast multicore machines we can get here too quick! Thread.Sleep(100); } }
/// <summary> /// Handles the MediaTransport.PropertyChanged event, which most of the time will be due to Position /// </summary> protected void MediaTransport_PropertyChanged(IPropertyObject sender, string property) { MediaTransport transport = sender as MediaTransport; MediaCenterEnvironment env = AddInHost.Current.MediaCenterEnvironment; MediaExperience exp = env.MediaExperience; HandlePropertyChange(env, exp, transport, property); }
/// <summary> /// Handles the MediaTransport.PropertyChanged event, which most of the time will be due to Position /// </summary> protected void MediaTransport_PropertyChanged(IPropertyObject sender, string property) { System.Diagnostics.Debug.Assert(Microsoft.MediaCenter.UI.Application.ApplicationThread == System.Threading.Thread.CurrentThread); MediaTransport transport = sender as MediaTransport; MediaCenterEnvironment env = Application.MediaCenterEnvironment; MediaExperience exp = env.MediaExperience; HandlePropertyChange(env, exp, transport, property); }
public void ResetConfig() { MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; DialogResult r = ev.Dialog("Are you sure you wish to reset all configuration to defaults?", "Reset Configuration", DialogButtons.Yes | DialogButtons.No, 60, true); if (r == DialogResult.Yes) { Config.Instance.Reset(); ev.Dialog("Please restart Media Browser", "Configuration Reset", DialogButtons.Ok, 60, true); Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication(); } }
/// <summary> /// Calls PlayMedia /// </summary> private bool CallPlayMediaLegacy(MediaCenterEnvironment mediaCenterEnvironment, PlayableItem playable) { Microsoft.MediaCenter.MediaType type = PlaybackControllerHelper.GetMediaType(playable); bool playedWithPlaylist = false; // Need to create a playlist if (PlaybackControllerHelper.RequiresWPL(playable)) { IEnumerable <string> files = playable.FilesFormattedForPlayer; string playlistFile = PlaybackControllerHelper.CreateWPLPlaylist(playable.Id.ToString(), files, playable.StartPlaylistPosition); if (!PlaybackControllerHelper.CallPlayMedia(mediaCenterEnvironment, type, playlistFile, false)) { return(false); } playedWithPlaylist = true; } // If we're playing a dvd and the last item played was a MediaCollection, we need to make sure the MediaCollection has // fully cleared out of the player or there will be quirks such as ff/rew remote buttons not working if (playable.HasMediaItems) { Video video = playable.MediaItems.First() as Video; Microsoft.MediaCenter.Extensibility.MediaType lastMediaType = PlaybackControllerHelper.GetCurrentMediaType(); if (video != null && video.MediaType == Library.MediaType.DVD && (lastMediaType == Microsoft.MediaCenter.Extensibility.MediaType.MediaCollection || lastMediaType == Microsoft.MediaCenter.Extensibility.MediaType.Unknown)) { System.Threading.Thread.Sleep(500); } } if (!playedWithPlaylist) { bool queue = false; foreach (string fileToPlay in playable.FilesFormattedForPlayer) { if (!PlaybackControllerHelper.CallPlayMedia(mediaCenterEnvironment, type, fileToPlay, queue)) { return(false); } queue = true; } } return(true); }
/// <summary> /// Calls PlayMedia using either a MediaCollection or a single file /// </summary> private bool CallPlayMediaForPlayableItem(MediaCenterEnvironment mediaCenterEnvironment, PlayableItem playable) { if (PlaybackControllerHelper.UseLegacyApi(playable)) { bool success = CallPlayMediaLegacy(mediaCenterEnvironment, playable); CurrentMediaCollection = null; return(success); } else { return(CallPlayMediaUsingMediaCollection(mediaCenterEnvironment, playable)); } }
public void NewPinEntered(bool pinCorrect) { MediaCenterEnvironment env = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; if (pinCorrect) { Logger.ReportInfo("Entering New PIN"); gettingNewPIN = true; //set flag Application.CurrentInstance.OpenSecurityPage(Application.CurrentInstance.StringData("EnterNewPINDial")); } else { env.Dialog(Application.CurrentInstance.StringData("IncorrectPINDial"), Application.CurrentInstance.StringData("CantChangePINDial"), DialogButtons.Ok, 60, true); Logger.ReportInfo("PIN Incorrect attempting change PIN "); } }
public void PlayPinEntered(bool pinCorrect) { Application.CurrentInstance.Back(); //clear the PIN page before playing MediaCenterEnvironment env = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; if (pinCorrect) { Logger.ReportInfo("Playing protected content " + anItem.Name); this.anItem.PlaySecure(resume, queue); } else { env.Dialog(Application.CurrentInstance.StringData("IncorrectPINDial"), Application.CurrentInstance.StringData("ContentProtected"), DialogButtons.Ok, 60, true); Logger.ReportInfo("Pin Incorrect attempting to play " + anItem.Name); } }
// Entry point for the app public void GoToMenu() { try { if (Config.IsFirstRun) { OpenConfiguration(false); MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; ev.Dialog("As this is the first time you have run Media Browser please setup the inital configuration", "Configure", DialogButtons.Ok, 60, true); } else { // We check config here instead of in the Updater class because the Config class // CANNOT be instantiated outside of the application thread. if (Config.EnableUpdates) { Updater update = new Updater(this); Async.Queue(update.checkUpdate); } Async.Queue(() => { using (new Profiler("Full Library Refresh")) { try { FullRefresh(this.RootFolder); } catch (Exception ex) { Logger.ReportException("Failed to refresh library! ", ex); Debug.Assert(false, "Full refresh thread should never crash!"); } } }); BaseItem initial = this.RootFolder; OpenFolderPage((MediaBrowser.Library.FolderModel)ItemFactory.Instance.Create(initial)); } } catch (Exception e) { Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog("Media Browser encountered a critical error and had to shut down: " + e.ToString() + " " + e.StackTrace.ToString(), "Critical Error", DialogButtons.Ok, 60, true); Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication(); } }
/// <summary> /// Displays a simple "OK" message box, branded with the Z logo. /// </summary> public void MessageBox(string text, string caption, int timeout, bool modal) { if (MediaCenterEnvironment == null) { Debug.WriteLine(String.Format("Dialog {0}: {1}", caption, text)); return; } MediaCenterEnvironment.Dialog( text, caption, new object[] { DialogButtons.Ok }, timeout, modal, "resx://Z,Version=7.0.0.0,PublicKeyToken=2f4e6f203aa84589,Culture=neutral/Z.Resources/ZLogoProgramLibrary", delegate(DialogResult dialogResult) { }); }
/// <summary> /// This is a workaround for when AddInHost.Current.MediaCenterEnvironment.MediaExperience returns null /// </summary> public static MediaExperience GetMediaExperienceUsingReflection() { MediaCenterEnvironment env = AddInHost.Current.MediaCenterEnvironment; var mce = env.MediaExperience; // great window 7 has bugs, lets see if we can work around them // http://mediacentersandbox.com/forums/thread/9287.aspx if (mce == null) { mce = env.MediaExperience; if (mce == null) { try { if (_CheckedMediaExperienceFIeldInfo == null) { _CheckedMediaExperienceFIeldInfo = env.GetType().GetField("_checkedMediaExperience", BindingFlags.NonPublic | BindingFlags.Instance); } if (_CheckedMediaExperienceFIeldInfo != null) { _CheckedMediaExperienceFIeldInfo.SetValue(env, false); mce = env.MediaExperience; } } catch (Exception e) { // give up ... I do not know what to do Logger.ReportException("AddInHost.Current.MediaCenterEnvironment.MediaExperience is null", e); } } if (mce == null) { Logger.ReportVerbose("GetMediaExperienceUsingReflection was unsuccessful"); } else { Logger.ReportVerbose("GetMediaExperienceUsingReflection was successful"); } } return(mce); }
public void UnwatchedPinEntered(bool pinCorrect) { Application.CurrentInstance.Back(); //clear the PIN page before playing MediaCenterEnvironment env = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; if (pinCorrect) { Logger.ReportInfo("Playing protected unwatched content " + anItem.Name); //add to list of protected folders we've entered addProtectedFolder(anItem as FolderModel); Application.CurrentInstance.PlayUnwatchedSecure(anItem); } else { env.Dialog(Application.CurrentInstance.StringData("IncorrectPINDial"), Application.CurrentInstance.StringData("ContentProtected"), DialogButtons.Ok, 60, true); Logger.ReportInfo("PIN Incorrect attempting to play unwatched in " + anItem.Name); } }
public void Launch(AddInHost host) { try { if (this.executionInfo.Media != null && this.executionInfo.Media.Count > 0) { bool flag = true; foreach (MediaInfo mediaInfo in this.executionInfo.Media) { MediaCenterEnvironment centerEnvironment = AddInHost.Current.MediaCenterEnvironment; MediaType?mediaType = mediaInfo.MediaType; int num1 = mediaType.HasValue ? (int)mediaType.GetValueOrDefault() : -1; string url = mediaInfo.Url; int num2 = !flag ? 1 : 0; centerEnvironment.PlayMedia((MediaType)num1, (object)url, num2 != 0); flag = false; } MediaExperience mediaExperience = AddInHost.Current.MediaCenterEnvironment.MediaExperience; if (mediaExperience != null) { mediaExperience.GoToFullScreen(); } } if (VmcExecuteAddIn.ExecutionEngine != null) { VmcExecuteAddIn.session = new HistoryOrientedPageSession(); ((PageSession)VmcExecuteAddIn.session).GoToPage("resx://Advent.VmcExecute/Advent.VmcExecute.Resources/MainPage"); VmcExecuteAddIn.ExecutionEngine.BeginExecute(); } else { if (!this.executionInfo.Page.HasValue) { return; } AddInHost.Current.MediaCenterEnvironment.NavigateToPage(this.executionInfo.Page.Value, (object)null); } } catch (Exception ex) { VmcExecuteAddIn.LogError(ex.ToString()); throw; } }
public void ClearCache() { MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; DialogResult r = ev.Dialog("Are you sure you wish to clear the cache?\nThis will erase all cached and downloaded information and images.", "Clear Cache", DialogButtons.Yes | DialogButtons.No, 60, true); if (r == DialogResult.Yes) { bool ok = Kernel.Instance.ItemRepository.ClearEntireCache(); if (!ok) { ev.Dialog("An error occured during the clearing of the cache, you may wish to manually clear it from " + ApplicationPaths.AppCachePath + " before restarting Media Browser", "Error", DialogButtons.Ok, 60, true); } else { ev.Dialog("Please restart Media Browser", "Cache Cleared", DialogButtons.Ok, 60, true); } Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication(); } }
private void Play(bool resume) { try { if (this.IsPlayable) { if (PlayableItem.PlaybackController != Application.CurrentInstance.PlaybackController) { Application.CurrentInstance.OpenExternalPlaybackPage(this); } this.PlayableItem.Play(this.PlayState, resume); } } catch (Exception) { MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; ev.Dialog("There was a problem playing the content. Check location exists\n" + baseItem.Path, "Content Error", DialogButtons.Ok, 60, true); } }
/// <summary> /// This is an oddity under TVPack, sometimes the MediaCenterEnvironemt and MediaExperience objects go bad and become /// disconnected from their host in the main application. Typically this is after 5 minutes of leaving the application idle (but noot always). /// What is odd is that using reflection under these circumstances seems to work - even though it is only doing the same as Reflector shoulds the real /// methods do. As I said it's odd but this at least lets us get a warning on the screen before the application crashes out! /// </summary> /// <param name="message"></param> public static void DialogBoxViaReflection(string message) { MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; FieldInfo fi = ev.GetType().GetField("_legacyAddInHost", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance); if (fi != null) { AddInHost2 ah2 = (AddInHost2)fi.GetValue(ev); if (ah2 != null) { Type t = ah2.GetType(); PropertyInfo pi = t.GetProperty("HostControl", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public); if (pi != null) { HostControl hc = (HostControl)pi.GetValue(ah2, null); hc.Dialog(message, "Media Browser", 1, 120, true); } } } }
public void DialogTest(string strClickedText) { int timeout = 5; bool modal = true; string caption = Resources.DialogCaption; if (session != null) { MediaCenterEnvironment.Dialog(strClickedText, caption, new object[] { DialogButtons.Ok }, timeout, modal, null, delegate(DialogResult dialogResult) { }); } else { Debug.WriteLine("DialogTest"); } }
public void CustomPINEntered(string aPIN) { //Logger.ReportInfo("Custom PIN entered: " + aPIN); if (gettingNewPIN) { gettingNewPIN = false; Config.Instance.ParentalPIN = aPIN; MediaCenterEnvironment env = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment; env.Dialog(Application.CurrentInstance.StringData("PINChangedDial"), Application.CurrentInstance.StringData("PINChangedCapDial"), DialogButtons.Ok, 60, true); Application.CurrentInstance.Back(); //clear PIN entry screen } else { pinCallback(aPIN == customPIN); if (pinCallback != UnlockPinEntered && aPIN == customPIN && aPIN == Config.Instance.ParentalPIN && Config.Instance.UnlockOnPinEntry) { //also unlock the library unlockLibrary(); Application.CurrentInstance.Information.AddInformationString(string.Format(Application.CurrentInstance.StringData("LibraryUnLockedProf"), this.unlockPeriod.ToString())); //and display a message } } }
public static void ResetMediaExperienceCache(MediaCenterEnvironment environment) { if (IsWindows7OrHigher) { try { FieldInfo fieldInfo = environment.GetType().GetField("_checkedMediaExperience", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo != null) { fieldInfo.SetValue(environment, false); } else { LogUtility.LogMessage("Warning: cannot find MediaCenterEnvironment._checkedMediaExperience field on Windows 7"); } } catch (Exception e) { LogUtility.LogMessage("Error setting MediaCenterEnvironment._checkedMediaExperience flag on Windows 7: " + e.ToString()); } } }
/// <summary> /// Handles a change of Playstate by firing various events and post play processes /// </summary> private void HandleStoppedState(MediaCenterEnvironment env, MediaExperience exp, MediaTransport transport, PlaybackStateEventArgs e) { Logger.ReportVerbose("In HandleStoppedState"); // Stop listening to the events env.PropertyChanged -= MediaCenterEnvironment_PropertyChanged; transport.PropertyChanged -= MediaTransport_PropertyChanged; Logger.ReportVerbose("Events unhooked"); // This will prevent us from getting in here twice after playback stops and calling post-play processes more than once. _HasStartedPlaying = false; _CurrentMediaCollection = null; var mediaType = exp.MediaType; // Check if internal wmc player is still playing, which could happen if the user launches live tv while playing something if (mediaType != Microsoft.MediaCenter.Extensibility.MediaType.TV) { Logger.ReportVerbose("Turning off NPV"); Application.CurrentInstance.ShowNowPlaying = false; if (mediaType == Microsoft.MediaCenter.Extensibility.MediaType.Audio || mediaType == Microsoft.MediaCenter.Extensibility.MediaType.DVD) { PlaybackControllerHelper.ReturnToApplication(true); } } else { Logger.ReportVerbose("Not turning off NPV because Live TV is playing."); } // Fire the OnFinished event for each item Async.Queue("Playback Finished", () => OnPlaybackFinished(e)); }
private void HandlePropertyChange(MediaCenterEnvironment env, MediaExperience exp, MediaTransport transport, string property) { PlayState state; long positionTicks = 0; // If another application is playing the content, such as the WMC autoplay handler, we will // not have permission to access Transport properties // But we can look at MediaExperience.MediaType to determine if something is playing try { state = transport.PlayState; positionTicks = transport.Position.Ticks; } catch (InvalidOperationException) { Logger.ReportVerbose("HandlePropertyChange was not able to access MediaTransport. Defaulting values."); state = exp.MediaType == Microsoft.MediaCenter.Extensibility.MediaType.Unknown ? Microsoft.MediaCenter.PlayState.Undefined : Microsoft.MediaCenter.PlayState.Playing; } bool playstateChanged = state != _CurrentPlayState; _CurrentPlayState = state; // Determine if playback has stopped. Per MSDN documentation, Finished is no longer used with Windows 7 bool isStopped = state == Microsoft.MediaCenter.PlayState.Finished || state == Microsoft.MediaCenter.PlayState.Stopped || state == Microsoft.MediaCenter.PlayState.Undefined; // Don't get tripped up at the initial state of Stopped with position 0 if (!_HasStartedPlaying) { if (!isStopped) { Logger.ReportVerbose("HandlePropertyChange has recognized that playback has started"); _HasStartedPlaying = true; if (Playable.HasMediaItems) Application.CurrentInstance.ReportPlaybackStart(Playable.CurrentMedia.ApiId); } else { return; } } // protect against really agressive calls if (property == "Position") { var diff = (DateTime.Now - _LastTransportUpdateTime).TotalMilliseconds; // Only cancel out Position reports if (diff < 5000 && diff >= 0) { return; } } _LastTransportUpdateTime = DateTime.Now; // Get metadata from player MediaMetadata metadata = exp.MediaMetadata; string metadataTitle = PlaybackControllerHelper.GetTitleOfCurrentlyPlayingMedia(metadata); long metadataDuration = PlaybackControllerHelper.GetDurationOfCurrentlyPlayingMedia(metadata); PlaybackStateEventArgs eventArgs = GetCurrentPlaybackState(metadataTitle, metadataDuration, positionTicks); // Only fire the progress handler while playback is still active, because once playback stops position will be reset to 0 OnProgress(eventArgs); Application.CurrentInstance.ShowNowPlaying = eventArgs.Item == null || eventArgs.Item.ShowNowPlayingView; if (playstateChanged) { // Get the title from the PlayableItem, if it's available. Otherwise use MediaMetadata string title = eventArgs.Item == null ? metadataTitle : (eventArgs.Item.HasMediaItems ? eventArgs.Item.MediaItems.ElementAt(eventArgs.CurrentMediaIndex).Name : eventArgs.Item.Files.ElementAt(eventArgs.CurrentFileIndex)); Logger.ReportVerbose("Playstate changed to {0} for {1}, PositionTicks:{2}, Playlist Index:{3}", state, title, positionTicks, eventArgs.CurrentFileIndex); PlayStateChanged(); Logger.ReportVerbose("Back from PlayStateChanged"); } if (isStopped) { Logger.ReportVerbose("Calling HandleStopedState"); HandleStoppedState(env, exp, transport, eventArgs); } }
/// <summary> /// Calls PlayMedia /// </summary> private bool CallPlayMediaLegacy(MediaCenterEnvironment mediaCenterEnvironment, PlayableItem playable) { Microsoft.MediaCenter.MediaType type = PlaybackControllerHelper.GetMediaType(playable); bool playedWithPlaylist = false; // Need to create a playlist if (PlaybackControllerHelper.RequiresWPL(playable)) { IEnumerable<string> files = playable.FilesFormattedForPlayer; string playlistFile = PlaybackControllerHelper.CreateWPLPlaylist(playable.Id.ToString(), files, playable.StartPlaylistPosition); if (!PlaybackControllerHelper.CallPlayMedia(mediaCenterEnvironment, type, playlistFile, false)) { return false; } playedWithPlaylist = true; } // If we're playing a dvd and the last item played was a MediaCollection, we need to make sure the MediaCollection has // fully cleared out of the player or there will be quirks such as ff/rew remote buttons not working if (playable.HasMediaItems) { Video video = playable.MediaItems.First() as Video; Microsoft.MediaCenter.Extensibility.MediaType lastMediaType = PlaybackControllerHelper.GetCurrentMediaType(); if (video != null && video.MediaType == Library.MediaType.DVD && (lastMediaType == Microsoft.MediaCenter.Extensibility.MediaType.MediaCollection || lastMediaType == Microsoft.MediaCenter.Extensibility.MediaType.Unknown)) { System.Threading.Thread.Sleep(500); } } if (!playedWithPlaylist) { bool queue = false; foreach (string fileToPlay in playable.FilesFormattedForPlayer) { if (!PlaybackControllerHelper.CallPlayMedia(mediaCenterEnvironment, type, fileToPlay, queue)) { return false; } queue = true; } } return true; }
private bool CallPlayMediaUsingMediaCollection(MediaCenterEnvironment mediaCenterEnvironment, PlayableItem playable) { MediaCollection coll = new MediaCollection(); // Create a MediaCollectionItem for each file to play if (playable.HasMediaItems) { PlaybackControllerHelper.PopulateMediaCollectionUsingMediaItems(this, coll, playable); } else { PlaybackControllerHelper.PopulateMediaCollectionUsingFiles(coll, playable); } // Set starting position if we're resuming if (playable.Resume) { var playstate = playable.MediaItems.First().PlaybackStatus; coll.CurrentIndex = playstate.PlaylistPosition; coll[playstate.PlaylistPosition].Start = new TimeSpan(playstate.PositionTicks); } _CurrentMediaCollection = coll; bool success = PlaybackControllerHelper.CallPlayMedia(mediaCenterEnvironment, MediaType.MediaCollection, _CurrentMediaCollection, false); if (!success) { _CurrentMediaCollection = null; } return success; }
/// <summary> /// Calls PlayMedia using either a MediaCollection or a single file /// </summary> private bool CallPlayMediaForPlayableItem(MediaCenterEnvironment mediaCenterEnvironment, PlayableItem playable) { if (PlaybackControllerHelper.UseLegacyApi(playable)) { bool success = CallPlayMediaLegacy(mediaCenterEnvironment, playable); _CurrentMediaCollection = null; return success; } else { return CallPlayMediaUsingMediaCollection(mediaCenterEnvironment, playable); } }
private static void WaitForStream(MediaCenterEnvironment mce) { int i = 0; while ((i++ < 15) && (mce.MediaExperience.Transport.PlayState != Microsoft.MediaCenter.PlayState.Playing)) { // settng the position only works once it is playing and on fast multicore machines we can get here too quick! Thread.Sleep(100); } }
public static bool CallPlayMedia(MediaCenterEnvironment mediaCenterEnvironment, Microsoft.MediaCenter.MediaType type, object media, bool queue) { string file = media.ToString(); Logger.ReportVerbose("Calling MediaCenterEnvironment.PlayMedia: " + file); return mediaCenterEnvironment.PlayMedia(type, media, queue); }
public static bool CallPlayMedia(MediaCenterEnvironment mediaCenterEnvironment, Microsoft.MediaCenter.MediaType type, object media, bool queue) { Logger.ReportVerbose("Calling MediaCenterEnvironment.PlayMedia"); return mediaCenterEnvironment.PlayMedia(type, media, queue); }