public static bool IsSupportedMedia(string path)
        {
            try
            {
                if (PathUtils.IsRootPath(path))
                {
                    DvdMedia dvdMedia = DvdMedia.FromPath(path);
                    if (dvdMedia != null)
                    {
                        return(true); // DVD's are supported media
                    }
                }

                if (Directory.Exists(path))
                {
                    return(FolderContainsMediaFiles(path));
                }
            }
            catch
            {
            }

            string ext = PathUtils.GetExtension(path);

            return(MediaRenderer.AllMediaTypes.Contains(ext));
        }
Beispiel #2
0
        private void btnOpenDvdFolder_Click(object sender, EventArgs e)
        {
            OPMFolderBrowserDialog dlg = new OPMFolderBrowserDialog();

            dlg.ShowNewFolderButton    = false;
            dlg.Description            = Translator.Translate("TXT_LOAD_DVD_FOLDER");
            dlg.PerformPathValidation += new PerformPathValidationHandler(dlg_PerformPathValidation);

            dlg.InheritAppIcon = false;
            dlg.Icon           = this.Icon;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    _selectedMedia = DvdMedia.FromPath(dlg.SelectedPath);
                }
                catch
                {
                    _selectedMedia = null;
                }

                if (_selectedMedia != null)
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    MessageDisplay.Show(Translator.Translate("TXT_INVALIDDVDVOLUME"),
                                        Translator.Translate("TXT_ERROR"), MessageBoxIcon.Warning);
                }
            }
        }
        public VideoFileInfo QueryVideoMediaInfo(string path)
        {
            VideoFileInfo vfi = null;

            DvdMedia dvdDrive = DvdMedia.FromPath(path);

            if (dvdDrive != null)
            {
                vfi = dvdDrive.VideoDvdInformation;
            }
            else
            {
                vfi = new VideoFileInfo(path, false);

                try
                {
                    if (vfi != null && vfi.IsValid)
                    {
                        Guid filterGraphGuid  = ProTONEConfig.FilterGraphGuid;
                        Type mediaControlType = Type.GetTypeFromCLSID(filterGraphGuid, true);

                        IMediaControl  mediaControl  = Activator.CreateInstance(mediaControlType) as IMediaControl;
                        IBasicAudio    basicAudio    = mediaControl as IBasicAudio;
                        IBasicVideo    basicVideo    = mediaControl as IBasicVideo;
                        IMediaPosition mediaPosition = mediaControl as IMediaPosition;

                        mediaControl.RenderFile(path);

                        double val = 0;
                        DsError.ThrowExceptionForHR(mediaPosition.get_Duration(out val));
                        vfi.Duration = TimeSpan.FromSeconds(val);

                        DsError.ThrowExceptionForHR(basicVideo.get_AvgTimePerFrame(out val));
                        vfi.FrameRate = new FrameRate(1f / val);

                        int h = 0, w = 0;
                        DsError.ThrowExceptionForHR(basicVideo.get_VideoHeight(out h));
                        DsError.ThrowExceptionForHR(basicVideo.get_VideoWidth(out w));
                        vfi.VideoSize = new VSize(w, h);

                        mediaControl.Stop();
                        mediaControl  = null;
                        mediaPosition = null;
                        basicVideo    = null;
                        basicAudio    = null;

                        GC.Collect();
                    }
                }
                catch
                {
                }
            }

            return(vfi);
        }
        public virtual void AddItem(string itemPath)
        {
            try
            {
                bool added = false;
                Uri  uri   = null;
                try
                {
                    uri = new Uri(itemPath, UriKind.Absolute);
                }
                catch
                {
                    uri = null;
                }

                if (uri != null)
                {
                    if (uri.IsFile)
                    {
                        itemPath = uri.LocalPath;
                    }
                    else
                    {
                        Add(new UrlPlaylistItem(itemPath));
                        added = true;
                    }
                }

                if (!added)
                {
                    if (DvdMedia.FromPath(itemPath) != null)
                    {
                        Add(new DvdPlaylistItem(itemPath));
                    }
                    else
                    {
                        Add(new PlaylistItem(itemPath, false));
                    }
                }

                EventRaiser(Count - 1, -1, UpdateType.Added);
                SetupRandomSequence(-1);
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchError(ex, true);
            }
            finally
            {
                Application.DoEvents();
            }
        }
Beispiel #5
0
        bool dlg_PerformPathValidation(string path)
        {
            try
            {
                // Check whether we can build a DVD media from that folder ...
                DvdMedia dvd = DvdMedia.FromPath(path);
                return(dvd != null);
            }
            catch
            {
            }

            return(false);
        }
Beispiel #6
0
        internal void AddFiles(IEnumerable <string> files)
        {
            if (_abortLoad)
            {
                return;
            }

            if (files != null)
            {
                foreach (string file in files)
                {
                    if (_abortLoad)
                    {
                        break;
                    }

                    if (DvdMedia.FromPath(file) != null)
                    {
                        playlist.AddItem(file);
                    }
                    else if (File.Exists(file))
                    {
                        if (IsPlaylist(file))
                        {
                            LoadPlaylist(file, true);
                        }
                        else
                        {
                            playlist.AddItem(file);
                        }
                    }
                    else if (Directory.Exists(file))
                    {
                        AddFiles(PathUtils.EnumDirectories(file));
                        AddFiles(PathUtils.EnumFiles(file));
                    }
                    else
                    {
                        playlist.AddItem(file);
                    }
                }
            }
        }
        public void SetRenderFile(string file)
        {
            try
            {
                _hasRenderingErrors = false;

                // Select the proper renderer for the specified media
                Uri uri = null;
                try
                {
                    uri = new Uri(file, UriKind.Absolute);
                }
                catch
                {
                    uri = null;
                }

                if (uri != null && !uri.IsFile)
                {
                    if (uri.OriginalString.StartsWith("dzmedia:///track/"))
                    {
                        CreateNewRenderer <DeezerRenderer>();
                    }
                    else
                    {
                        using (ShoutcastStream ss = new ShoutcastStream(file, 4000, false))
                        {
                            if (ss.Connected)
                            {
                                CreateNewRenderer <DSShoutcastRenderer>();
                            }
                            else
                            {
                                // Media file exposed as URL
                                CreateNewRenderer <DSFileRenderer>();
                            }
                        }
                    }
                }
                else
                {
                    if (DvdMedia.FromPath(file) != null)
                    {
                        CreateNewRenderer <DSDvdRenderer>();
                    }
                    else
                    {
                        string streamType = PathUtils.GetExtension(file).ToLowerInvariant();
                        if (streamType == "cda")
                        {
                            CreateNewRenderer <DSAudioCDRenderer>();
                        }
                        else
                        {
                            CreateNewRenderer <DSFileRenderer>();
                        }
                    }
                }

                Logger.LogTrace("Now playing media: {0}", file);

                if (streamRenderer != null)
                {
                    streamRenderer.RenderRegion = renderPanel;

                    if (this.FilterState == OPMedia.Runtime.ProTONE.Rendering.DS.BaseClasses.FilterState.Stopped)
                    {
                        streamRenderer.RenderMediaName = file;
                    }
                }
            }
            catch (Exception ex)
            {
                ReportRenderingException(ex);
            }
        }
Beispiel #8
0
        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();
                }
            }
        }