示例#1
0
        /// <summary>
        /// Concise way of flushing and then updating the distribution point's metadata
        /// </summary>
        /// <param name="MetadataInstance">A ShoutcastMetadata instance with the new data to send to the server, with all desired fields filled out.</param>
        public void PerformMetadataUpdate(ShoutcastMetadata MetadataInstance)
        {
            FlushCachedMetadata();

            var XmlNamespaces = new XmlSerializerNamespaces();

            XmlNamespaces.Add("", "");

            XmlSerializer Serializer = new XmlSerializer(typeof(ShoutcastMetadata));
            StringBuilder Sb         = new StringBuilder();

            int MetadataId    = 1;
            int MetadataSpan  = 1;
            int MetadataIndex = 1;

            byte[] XmlHead = new byte[] { 0x0, Convert.ToByte(MetadataId), 0x0, Convert.ToByte(MetadataSpan), 0x0, Convert.ToByte(MetadataIndex) };
            byte[] XmlBytes;

            using (StringWriter Writer = new StringWriter(Sb))
            {
                Serializer.Serialize(Writer, MetadataInstance, XmlNamespaces);
                XmlBytes = Encoding.UTF8.GetBytes(Writer.ToString().Replace("utf-16", "UTF-8"));
                Array.Resize <byte>(ref XmlBytes, XmlBytes.Length + 6);

                Buffer.BlockCopy(XmlBytes, 0, XmlBytes, 6, XmlBytes.Length - 6);
                Buffer.BlockCopy(XmlHead, 0, XmlBytes, 0, 6);
            }

            Console.WriteLine(Encoding.UTF8.GetString(XmlBytes));

            SourceSocket.Send(Packet.Serialize(MessageFlag.ShoutcastXmlMetadata, XmlBytes));
        }
示例#2
0
        // Just a quick-and-dirty example. You don't have to wrap this in a class, obviously, the below code can be used anywhere that Netshout is accessible.
        // The intended user of this application should be able to recognize that, though 8)

        public Example()
        {
            Broadcast Bc = new Broadcast("UID", "Password", new System.Net.IPEndPoint(System.Net.IPAddress.Parse("EndpointIp"), 8000), 1);

            Console.WriteLine("Authenticating..");

            try
            {
                Bc.AuthenticateStream();
            }

            catch (AuthDenyException E)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(E.Message);
                Console.ForegroundColor = ConsoleColor.White;

                while (true)
                {
                    Console.ReadLine();
                }
            }

            if (!Bc.Authenticated)
            {
                return;
            }

            Console.WriteLine("Setting MIME type..");
            Bc.SetMimeType(MimeType.Mp3);
            Console.WriteLine("Mime type: " + MimeType.Mp3);

            Console.WriteLine("Setting Bitrate..");
            Bc.SetBitrate(320, 320);

            Bc.NegotiateMaxPayloadSize((16 * 1024) - 6 - 1, 0);

            Console.Write("Negotiating buffer size..");
            Bc.NegotiatedBufferSize = Bc.NegotiateBufferSize(1024, 2048);
            Console.WriteLine();

            Bc.IcyName  = "Netshout Test Broadcast";
            Bc.IcyGenre = "Various";
            Bc.IcyPub   = false;
            Bc.IcyUrl   = "http://dev.nodebay.com";

            ShoutcastMetadata Scmd = new ShoutcastMetadata();

            Scmd.Track            = "X";
            Scmd.Album            = "Test Album";
            Scmd.StreamTitle      = "Netshout Library Test Session";
            Scmd.SourceIdentifier = "Netshout Source Library";

            Bc.Standby();
            Bc.PerformMetadataUpdate(Scmd);

            if (!Bc.StreamReady)
            {
                return;
            }

            while (true)
            {
                Console.ReadLine();
            }
        }