protected override void DoStartRenderer() { if (renderMediaName == null || renderMediaName.Length <= 0) { return; } renderMediaInfo = MediaFileInfo.FromPath(renderMediaName, true); GC.Collect(); InitMedia(); InitAudioAndVideo(); int hr = mediaPosition.put_Rate(1); DsError.ThrowExceptionForHR(hr); // Run the graph to play the media file hr = mediaControl.Run(); DsError.ThrowExceptionForHR(hr); // HACK: call GetMedialenght once here to ensure that durationScaleFactor is buuilt up double len = GetMediaLength(); }
private bool TestFile(string file) { if (_shouldCancelSearch.WaitOne(0)) { return(false); } if (file == null || File.Exists(file) == false) { return(false); } if (SearchBookmarksActive()) { BookmarkFileInfo bfi = new BookmarkFileInfo(file, false); if (bfi == null || !bfi.IsValid || (theTask.Option1 && bfi.IsOrphan) || /* for BMK files: option 1 = non-orphan bookmarks */ (theTask.Option2 && !bfi.IsOrphan)) /* for BMK files: option 2 = orphan bookmarks */ { return(false); // skip this file } } else if (SearchMediaFilesActive()) { if (!MediaRenderer.IsSupportedMedia(file)) { return(false); // not a media file } MediaFileInfo mfi = MediaFileInfo.FromPath(file); if (mfi == null || !mfi.IsValid || (theTask.Option1 && mfi.Bookmarks.Count < 1) || /* for media files: option 1 = files with bookmarks */ (theTask.Option2 && mfi.Bookmarks.Count > 0)) /* for media files: option 2 = files w/o bookmarks */ { return(false); // skip this file } } if (!theTask.UseAttributes || AttributesMatch(File.GetAttributes(file), true)) { bool match = (theTask.SearchText.Length == 0) || (theTask.SearchProperties && ContainsProperty(file)) || (!theTask.SearchProperties && ContainsText(file)); if (match && !_matchingItems.Contains(file.ToLowerInvariant())) { _matchingItems.Add(file.ToLowerInvariant()); _displayItems.Add(file); return(true); } } return(false); }
public PlaylistItem(string itemPath, bool isDvd, bool deepLoad) { if (isDvd) { mi = new VideoDvdInformation(itemPath); } else { mi = MediaFileInfo.FromPath(itemPath, deepLoad); } }
private bool ContainsProperty(string file) { if (_shouldCancelSearch.WaitOne(0)) { return(false); } try { // So far only media files can have "text" properties if (MediaRenderer.IsSupportedMedia(file)) { MediaFileInfo mfi = MediaFileInfo.FromPath(file); if (mfi != null) { foreach (KeyValuePair <string, string> kvp in mfi.ExtendedInfo) { string keyword = theTask.SearchText; string name = kvp.Key; string value = kvp.Value; if (theTask.IsCaseInsensitive) { keyword = keyword != null?keyword.ToLowerInvariant() : string.Empty; name = name != null?name.ToLowerInvariant() : string.Empty; value = value != null?value.ToLowerInvariant() : string.Empty; } if (name.Contains(keyword) || value.Contains(keyword)) { return(true); } } } } return(false); } finally { GC.Collect(); } }
string opmShellList_QueryDisplayName(string fsi) { if (fsi != null) { if (fsi.ToUpperInvariant().EndsWith("CDA")) { CDAFileInfo cdfi = MediaFileInfo.FromPath(fsi) as CDAFileInfo; if (cdfi != null) { return(cdfi.DisplayName); } } return(Path.GetFileName(fsi)); } return(string.Empty); }
public void DoTranscoding(EncoderSettings encoderSettings, string inputFile) { _grabber = CdRipper.CreateGrabber(OutputFormat); if (_grabber == null) { throw new NotSupportedException(string.Format("TXT_UNSUPPORTED_OUTPUT_FORMAT: {0}", InputFormat)); } switch (InputFormat) { case AudioMediaFormatType.WAV: switch (OutputFormat) { case AudioMediaFormatType.MP3: { // Transcode WAV => MP3 i.o.w encode the wav WaveFormatEx wfex = WaveFormatEx.Cdda; byte[] buff = WaveFile.ReadWaveData(inputFile, ref wfex); GrabberToMP3 grabber = (_grabber as GrabberToMP3); grabber.Options = (encoderSettings as Mp3EncoderSettings).Options; // Resample is not supported at this time. // Specify the same settings as the input WAV file, otherwise we'll be failing. grabber.Options.WaveFormat = wfex; grabber.EncodeBuffer(buff, Path.ChangeExtension(inputFile, "MP3"), false, null); return; } } break; case AudioMediaFormatType.MP3: switch (OutputFormat) { case AudioMediaFormatType.WAV: // Transcode MP3 => WAV i.o.w decode the MP3 string outputFile = Path.ChangeExtension(inputFile, "WAV"); if (DecodeMP3ToWAV(inputFile, outputFile) == false) { throw new Exception("TXT_FAILED_CONVERSION_MP3_WAV"); } return; case AudioMediaFormatType.MP3: { // Transcode MP3 => MP3 i.o.w adjust MP3 encoding string tempWavFile = Path.GetTempFileName(); if (DecodeMP3ToWAV(inputFile, tempWavFile) == false) { throw new Exception("TXT_FAILED_CONVERSION_MP3_TEMP_WAV"); } WaveFormatEx wfex = WaveFormatEx.Cdda; byte[] buff = WaveFile.ReadWaveData(tempWavFile, ref wfex); GrabberToMP3 grabber = (_grabber as GrabberToMP3); grabber.Options = (encoderSettings as Mp3EncoderSettings).Options; ID3FileInfoSlim ifiSlim = new ID3FileInfoSlim(MediaFileInfo.FromPath(inputFile, false)); grabber.EncodeBuffer(buff, Path.ChangeExtension(inputFile, "REENC.MP3"), (encoderSettings as Mp3EncoderSettings).CopyInputFileMetadata, ifiSlim); if (File.Exists(tempWavFile)) { File.Delete(tempWavFile); } return; } } break; } throw new NotSupportedException(string.Format("TXT_UNSUPPORTED_TRANSCODING: {0}", this)); }
internal void PlayFile(string strFile, PlaylistSubItem subItem) { if (!string.IsNullOrEmpty(strFile)) { if (subItem == null && MediaRenderer.DefaultInstance.FilterState != FilterState.Stopped) { Stop(false); } bool isVideoFile = false; bool isDVDVolume = false; string name = string.Empty; DvdMedia dvdDrive = DvdMedia.FromPath(strFile); if (dvdDrive != null) { isDVDVolume = true; name = dvdDrive.ToString(); if (subItem != null && subItem.StartHint != null) { name += Translator.Translate("TXT_PLAY_FROM", subItem.StartHint); } } else { MediaFileInfo mfi = MediaFileInfo.FromPath(strFile); isVideoFile = MediaRenderer.SupportedVideoTypes.Contains(mfi.MediaType); // PlaylistItem pli = pnlScreens.PlaylistScreen.GetActivePlaylistItem(); if (pli != null) { name = pli.DisplayName; } else { name = mfi.Name; } } if (isDVDVolume) { Logger.LogTrace("Played media appears to be a DVD volume ..."); } else if (isVideoFile) { Logger.LogTrace("Played media appears to be a video file ..."); } else { Logger.LogTrace("Played media appears to be an audio file..."); } if (isVideoFile || isDVDVolume) { ShowRenderingRegion(); } else { HideRenderingRegion(); } if (NotifyMediaStateChanged != null) { NotifyMediaStateChanged(isVideoFile || isDVDVolume); } MediaRenderer.DefaultInstance.SetRenderFile(strFile); bool rendererStarted = false; if (subItem != null && subItem.StartHint != null) { MediaRenderer.DefaultInstance.StartRendererWithHint(subItem.StartHint); rendererStarted = true; } if (!rendererStarted) { MediaRenderer.DefaultInstance.StartRenderer(); } if (MediaRenderer.DefaultInstance.HasRenderingErrors == false) { if (_renderingFrame != null && (isVideoFile || isDVDVolume)) { if (!_renderingFrame.Visible) { _renderingFrame.Show(); } } SetVolume(pnlRendering.ProjectedVolume); if (subItem != null && subItem.StartHint != null) { NotifyGUI("TXT_OSD_PLAY", subItem); } else { NotifyGUI("TXT_OSD_PLAY", name); } if (isVideoFile) { if (_delayedSubtitleLookupTimer == null) { _delayedSubtitleLookupTimer = new System.Windows.Forms.Timer(); _delayedSubtitleLookupTimer.Interval = 1000; _delayedSubtitleLookupTimer.Tick += new EventHandler(_delayedSubtitleLookupTimer_Tick); } _delayedSubtitleLookupTimer.Start(); } } else { HideRenderingRegion(); } } }
private void LoadFiles() { OPMOpenFileDialog dlg = new OPMOpenFileDialog(); dlg.Title = Translator.Translate("TXT_LOADMEDIAFILES"); dlg.Multiselect = true; dlg.InheritAppIcon = false; dlg.Icon = Resources.btnLoad.ToIcon((uint)Color.White.ToArgb()); string filter = string.Empty; filter += MediaRenderer.DefaultInstance.AvailableFileTypesFilter; filter += Translator.Translate("TXT_ALL_FILES_FILTER"); filter = filter.Replace("TXT_AUDIO_FILES", Translator.Translate("TXT_AUDIO_FILES")); filter = filter.Replace("TXT_VIDEO_FILES", Translator.Translate("TXT_VIDEO_FILES")); filter = filter.Replace("TXT_VIDEO_HD_FILES", Translator.Translate("TXT_VIDEO_HD_FILES")); filter = filter.Replace("TXT_PLAYLISTS", Translator.Translate("TXT_PLAYLISTS")); dlg.Filter = filter; dlg.FilterIndex = ProTONEConfig.LastFilterIndex; dlg.InitialDirectory = ProTONEConfig.LastOpenedFolder; dlg.FillFavoriteFoldersEvt += () => { return(ProTONEConfig.GetFavoriteFolders("FavoriteFolders")); }; dlg.AddToFavoriteFolders += (s) => { return(ProTONEConfig.AddToFavoriteFolders(s)); }; dlg.QueryDisplayName += (fsi) => { if (fsi != null) { if (fsi.ToUpperInvariant().EndsWith("CDA")) { CDAFileInfo cdfi = MediaFileInfo.FromPath(fsi) as CDAFileInfo; if (cdfi != null) { return(cdfi.DisplayName); } } return(Path.GetFileName(fsi)); } return(string.Empty); }; dlg.ShowAddToFavorites = true; dlg.OpenDropDownOptions = new List <OpenOption>(new OpenOption[] { new MediaPlayerOpenOption(CommandType.PlayFiles), new MediaPlayerOpenOption(CommandType.EnqueueFiles) }); if (dlg.ShowDialog() == DialogResult.OK && dlg.FileNames.Length > 0) { CommandType openOption = CommandType.PlayFiles; try { openOption = (CommandType)dlg.OpenOption; } catch { openOption = CommandType.PlayFiles; } if (openOption == CommandType.EnqueueFiles) { EnqueueFiles(dlg.FileNames); } else { LoadFiles(dlg.FileNames); } ProTONEConfig.LastFilterIndex = dlg.FilterIndex; try { string file = dlg.FileNames[0]; ProTONEConfig.LastOpenedFolder = Path.GetDirectoryName(file); } catch { ProTONEConfig.LastOpenedFolder = dlg.InitialDirectory; } } }