Exemplo n.º 1
0
    // This is the completion part of the async callback invoked
    // in DoRead to process a new meta entry.
    static private void CallbackMethod(IAsyncResult ar)
    {
        // Retrieve the delegate.
        AsyncResult      result = (AsyncResult)ar;
        LoadValuesCaller caller = (LoadValuesCaller)result.AsyncDelegate;

        // Call EndInvoke to end the call.
        caller.EndInvoke(ar);
    }
Exemplo n.º 2
0
    public IcyScheme(string sUrl)
    {
        m_Position     = 0;
        m_SinceLast    = 0;
        m_bShutdown    = false;
        m_uri          = new Uri(sUrl);
        m_ConnectEvent = new ManualResetEvent(false);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_uri);
        ServicePoint   point   = request.ServicePoint;

        point.ReceiveBufferSize = DefaultReceiveBufferSize * 2;
        request.UserAgent       = "NSPlayer/12.00.7601.23471";
        request.Headers.Add("Icy-Metadata:1");

        bool OldUnsafe, UseOldUnsafe;

        UseOldUnsafe = AllowUnsafeHeaderParsing(true, out OldUnsafe);

        // Parts of BeginGetResponse are still done synchronously,
        // so we do it this way.
        Task.Factory.FromAsync <WebResponse>(request.BeginGetResponse,
                                             request.EndGetResponse,
                                             null)
        .ContinueWith(task =>
        {
            if (UseOldUnsafe)
            {
                AllowUnsafeHeaderParsing(OldUnsafe, out OldUnsafe);
            }

            if (task.Status == TaskStatus.RanToCompletion)
            {
                try
                {
                    WebResponse wr = task.Result;

                    // Turn the headers into metadata, plus store them as an
                    // IMFAttribute
                    LoadResponseHeaders(wr.Headers);

                    // The only part of the HttpWebRequest that we keep.
                    m_ResponseStream = wr.GetResponseStream();

                    // In order to (pretend  to) support seeking, we save off a block
                    // of data.  Any seeks to the first DefaultReceiveBufferSize bytes
                    // are resolved from this data.
                    m_PositionReal = long.MaxValue;
                    m_FirstBlock   = new byte[DefaultReceiveBufferSize];
                    WaitRead(m_FirstBlock, 0, DefaultReceiveBufferSize);
                    m_PositionReal = 0;

                    // Used to tell WaitForConnect that the connection is complete.
                    m_ConnectEvent.Set();
                }
                catch
                {
                    Dispose();
                }
            }
            else
            {
                Dispose();
            }
        });

        // While we are waiting for the connect/cache to complete, finish
        // the constructor.

        m_MetaData = new MetaDataContainer();
        MFError hrthrowonerror = MFExtern.MFCreateEventQueue(out m_events);

        m_FixNames = new Dictionary <string, string>(13);

        // Note that the keys are (intentionally) all lower case.
        m_FixNames["icy-name"]                = "WM/RadioStationName";
        m_FixNames["x-audiocast-name"]        = "WM/RadioStationName";
        m_FixNames["icy-genre"]               = "WM/Genre";
        m_FixNames["x-audiocast-genre"]       = "WM/Genre";
        m_FixNames["icy-url"]                 = "WM/PromotionURL";
        m_FixNames["x-audiocast-url"]         = "WM/PromotionURL";
        m_FixNames["x-audiocast-description"] = "Description";
        m_FixNames["x-audiocast-artist"]      = "Author";
        m_FixNames["x-audiocast-album"]       = "WM/AlbumTitle";
        m_FixNames["x-audiocast-br"]          = "BitRate";
        m_FixNames["icy-br"]      = "BitRate";
        m_FixNames["streamtitle"] = "Title";
        m_FixNames["streamurl"]   = "WM/AudioFileURL";

        hrthrowonerror = SetString(
            MFAttributesClsid.MF_BYTESTREAM_EFFECTIVE_URL,
            m_uri.AbsoluteUri);

        // Use this to make async calls to handle meta data.
        m_caller = new LoadValuesCaller(LoadValues);
    }