public AVPlayList(AVRenderer AVR, IMediaResource[] r, ReadyHandler rh, FailedHandler fh, object Tag)
        {
            OpenSource.Utilities.InstanceTracker.Add(this);
            _AVR = AVR;
            string UseThisProtocolInfo = "";

            _Tag = Tag;

            /*
             * ArrayList branches = new ArrayList();
             * ToXmlData_Custom txdc = new ToXmlData_Custom();
             * foreach(IMediaResource R in r)
             * {
             *  if(branches.Contains(R.Owner)==false)
             *  {
             *      branches.Add(R.Owner);
             *  }
             *  txdc.Mappings[R] = false;
             * }
             *
             * MediaBuilder.container container = new MediaBuilder.container("Autogenerated Playlist");
             * container.ID = Guid.NewGuid().ToString();
             * container.IdIsValid = true;
             * ToXmlFormatter txf = new ToXmlFormatter();
             * txf.WriteResource = new ToXmlFormatter.ToXml_FormatResource(WriteResource);
             * txdc.DesiredProperties = new ArrayList();
             * txdc.IsRecursive = true;
             * txdc.VirtualOwner =  MediaBuilder.CreateContainer(container);
             *
             * // Obtain the DIDL-Lite MetaData
             * this.PlayListMetaData = MediaBuilder.BuildDidl(txf, txdc, branches);
             * if(PlayListMetaData.Length>32768) PlayListMetaData = "";
             */

            int  TempHandle = this.GetHashCode();
            bool Done       = false;

            OnReady  += rh;
            OnFailed += fh;

            //Subscribe to the internal events on the Renderer to initiate a connection
            AVR.OnCreateConnection2       += new AVRenderer.ConnectionHandler(ConnectionSink);
            AVR.OnRecycledConnection2     += new AVRenderer.ConnectionHandler(RecycledSink);
            AVR.OnCreateConnectionFailed2 += new AVRenderer.FailedConnectionHandler(FailedSink);

            if (r.Length == 1)
            {
                // There is only one resource, so no need to build a playlist
                Done = true;
                _CurrentPlayListMode = PlayListMode.NOT_A_PLAYLIST;
                PlayListUri          = ConvertLocalFileToHTTPResource(r[0]);
                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    AVR.CreateConnection(r[0].ProtocolInfo.ToString(), "", -1, TempHandle);
                }
            }

            if ((Done == false && AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/mpegurl:*")))
                ||
                (Done == false && AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/x-mpegurl:*"))))
            {
                // Build M3U
                Done = true;
                _CurrentPlayListMode = PlayListMode.M3U;

                CheckMiniWebServer();

                //OpenSource.Utilities.InstanceTracker.StartTimer();

                StringBuilder M3U = new StringBuilder();
                if (AVPlayList.EnableExtendedM3U)
                {
                    M3U.Append("#EXTM3U\r\n");
                }
                foreach (IMediaResource R in r)
                {
                    if (AVPlayList.EnableExtendedM3U)
                    {
                        PrintExtInfLine(M3U, R);
                    }
                    M3U.Append(ConvertLocalFileToHTTPResource(R) + "\r\n");
                }

                M3UString = M3U.ToString();

                //OpenSource.Utilities.InstanceTracker.StopTimer("Build M3U");

                PlayListUri = "http://" + AVR.Interface.ToString() + ":" + MWS.LocalIPEndPoint.Port.ToString() + "/item.m3u";

                if (AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/x-mpegurl:*")))
                {
                    UseThisProtocolInfo = "http-get:*:audio/x-mpegurl:*";
                }
                if (AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/mpegurl:*")))
                {
                    UseThisProtocolInfo = "http-get:*:audio/mpegurl:*";
                }

                //OpenSource.Utilities.InstanceTracker.StartTimer();

                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    AVR.CreateConnection(UseThisProtocolInfo, "/", -1, TempHandle);
                }
            }

            if (Done == false)
            {
                // Fake a play list by switching Uri's on the fly

                _CurrentPlayListMode = PlayListMode.SINGLE_URI;
                foreach (IMediaResource rsc in r)
                {
                    FakePlayQueue.Enqueue(rsc);
                }
                PlayListUri = r[0].ContentUri;
                FakePlayQueue.Dequeue();
                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    AVR.CreateConnection(r[0].ProtocolInfo.ToString(), "/", -1, TempHandle);
                }
            }
        }
Beispiel #2
0
        public AVPlayList(AVRenderer AVR, IMediaResource[] r, ReadyHandler rh, FailedHandler fh, object Tag)
        {
            OpenSource.Utilities.InstanceTracker.Add(this);
            _AVR = AVR;
            string UseThisProtocolInfo = "";
            _Tag = Tag;

            /*
            ArrayList branches = new ArrayList();
            ToXmlData_Custom txdc = new ToXmlData_Custom();
            foreach(IMediaResource R in r)
            {
                if(branches.Contains(R.Owner)==false)
                {
                    branches.Add(R.Owner);
                }
                txdc.Mappings[R] = false;
            }

            MediaBuilder.container container = new MediaBuilder.container("Autogenerated Playlist");
            container.ID = Guid.NewGuid().ToString();
            container.IdIsValid = true;
            ToXmlFormatter txf = new ToXmlFormatter();
            txf.WriteResource = new ToXmlFormatter.ToXml_FormatResource(WriteResource);
            txdc.DesiredProperties = new ArrayList();
            txdc.IsRecursive = true;
            txdc.VirtualOwner =  MediaBuilder.CreateContainer(container);
			
            // Obtain the DIDL-Lite MetaData
            this.PlayListMetaData = MediaBuilder.BuildDidl(txf, txdc, branches);
            if(PlayListMetaData.Length>32768) PlayListMetaData = "";
            */

            int TempHandle = this.GetHashCode();
            bool Done = false;
            OnReady += rh;
            OnFailed += fh;

            //Subscribe to the internal events on the Renderer to initiate a connection
            AVR.OnCreateConnection2 += new AVRenderer.ConnectionHandler(ConnectionSink);
            AVR.OnRecycledConnection2 += new AVRenderer.ConnectionHandler(RecycledSink);
            AVR.OnCreateConnectionFailed2 += new AVRenderer.FailedConnectionHandler(FailedSink);

            if (r.Length == 1)
            {
                // There is only one resource, so no need to build a playlist
                Done = true;
                _CurrentPlayListMode = PlayListMode.NOT_A_PLAYLIST;
                PlayListUri = ConvertLocalFileToHTTPResource(r[0]);
                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    AVR.CreateConnection(r[0].ProtocolInfo.ToString(), "", -1, TempHandle);
                }
            }

            if ((Done == false && AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/mpegurl:*")))
                ||
                (Done == false && AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/x-mpegurl:*"))))
            {
                // Build M3U
                Done = true;
                _CurrentPlayListMode = PlayListMode.M3U;

                CheckMiniWebServer();

                //OpenSource.Utilities.InstanceTracker.StartTimer();

                StringBuilder M3U = new StringBuilder();
                if (AVPlayList.EnableExtendedM3U)
                {
                    M3U.Append("#EXTM3U\r\n");
                }
                foreach (IMediaResource R in r)
                {
                    if (AVPlayList.EnableExtendedM3U)
                    {
                        PrintExtInfLine(M3U, R);
                    }
                    M3U.Append(ConvertLocalFileToHTTPResource(R) + "\r\n");
                }

                M3UString = M3U.ToString();

                //OpenSource.Utilities.InstanceTracker.StopTimer("Build M3U");

                PlayListUri = "http://" + AVR.Interface.ToString() + ":" + MWS.LocalIPEndPoint.Port.ToString() + "/item.m3u";

                if (AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/x-mpegurl:*")))
                    UseThisProtocolInfo = "http-get:*:audio/x-mpegurl:*";
                if (AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/mpegurl:*")))
                    UseThisProtocolInfo = "http-get:*:audio/mpegurl:*";

                //OpenSource.Utilities.InstanceTracker.StartTimer();

                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    AVR.CreateConnection(UseThisProtocolInfo, "/", -1, TempHandle);
                }
            }

            if (Done == false)
            {
                // Fake a play list by switching Uri's on the fly

                _CurrentPlayListMode = PlayListMode.SINGLE_URI;
                foreach (IMediaResource rsc in r)
                {
                    FakePlayQueue.Enqueue(rsc);
                }
                PlayListUri = r[0].ContentUri;
                FakePlayQueue.Dequeue();
                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    AVR.CreateConnection(r[0].ProtocolInfo.ToString(), "/", -1, TempHandle);
                }
            }
        }