Exemplo n.º 1
0
        /// <summary>
        ///     Starts a video.
        /// </summary>
        /// <param name="filePath">The URL of the video to play.</param>
        /// <param name="mediaStreamingServer"></param>
        /// <param name="startPosition">The start position of the video. This value must be between 0 and 1</param>
        public void StartVideo(Uri filePath, MediaStreamingServer mediaStreamingServer, float startPosition = 0)
        {
            StreamingVideo = true;
            if (startPosition > 1)
            {
                throw new ArgumentException("Start Position must be between 0 and 1");
            }

            var tcpClient = new TcpClient(IpAddress, DevicePort)
            {
                ReceiveTimeout = 5000,
                SendTimeout    = 5000
            };

            //get the client stream to read data from.
            var clientStream = tcpClient.GetStream();

            var url  = mediaStreamingServer.Address + "/play?filePath=" + filePath.AbsolutePath;
            var body = "Content-Location: " + url + "\n" +
                       "Start-Position: " + startPosition + "\n";

            var request = "POST /play HTTP/1.1\n" +
                          "User-Agent: MediaControl/1.0\n" +
                          "Content-Type: text/parameters\n" +
                          "Content-Length: " + Encoding.ASCII.GetBytes(body).Length + "\n" +
                          "X-Apple-Session-ID:" + Id + "\n\n";

            //Send the headers
            SendMessage(clientStream, request);
            //Send the body
            SendMessage(clientStream, body);

            //Get the response
            var myReadBuffer      = new byte[1024];
            var myCompleteMessage = new StringBuilder();
            var numberOfBytesRead = 0;

            numberOfBytesRead = clientStream.Read(myReadBuffer, 0, myReadBuffer.Length);
            myCompleteMessage.Append(Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));

            //Now start doing a "keepalive"
            while (true)
            {
                if (Stop)
                {
                    tcpClient.Close();
                    clientStream.Close();
                    Stop           = false;
                    StreamingVideo = false;
                    return;
                }
                //Simply send the characters "ok" every two seconds
                SendMessage(clientStream, "ok");
                Thread.Sleep(2000);
            }
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();
            airplayDevices             = new ObservableCollection <AirplayDevice>();
            airPlayDevices.ItemsSource = airplayDevices;
            var airPlayDiscovery = new AirPlayDiscovery();

            airPlayDiscovery.AirplayServiceFound += ServiceDiscoveryAirplayServiceFound;
            mediaStreamingServer = new MediaStreamingServer().Start();
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Starts a video.
        /// </summary>
        /// <param name="filePath">The URL of the video to play.</param>
        /// <param name="mediaStreamingServer"></param>
        /// <param name="startPosition">The start position of the video. This value must be between 0 and 1</param>
        public void StartVideo(Uri filePath, MediaStreamingServer mediaStreamingServer, float startPosition = 0)
        {
            StreamingVideo = true;
            if (startPosition > 1)
            {
                throw new ArgumentException("Start Position must be between 0 and 1");
            }

            var tcpClient = new TcpClient(IpAddress, DevicePort)
            {
                ReceiveTimeout = 5000,
                SendTimeout = 5000
            };

            //get the client stream to read data from.
            var clientStream = tcpClient.GetStream();

            var url = mediaStreamingServer.Address + "/play?filePath=" + filePath.AbsolutePath;
            var body = "Content-Location: " + url + "\n" +
                       "Start-Position: " + startPosition + "\n";

            var request = "POST /play HTTP/1.1\n" +
                          "User-Agent: MediaControl/1.0\n" +
                          "Content-Type: text/parameters\n" +
                          "Content-Length: " + Encoding.ASCII.GetBytes(body).Length + "\n" +
                          "X-Apple-Session-ID:" + Id + "\n\n";

            //Send the headers
            SendMessage(clientStream, request);
            //Send the body
            SendMessage(clientStream, body);

            //Get the response
            var myReadBuffer = new byte[1024];
            var myCompleteMessage = new StringBuilder();
            var numberOfBytesRead = 0;
            numberOfBytesRead = clientStream.Read(myReadBuffer, 0, myReadBuffer.Length);
            myCompleteMessage.Append(Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));

            //Now start doing a "keepalive"
            while (true)
            {
                if (Stop)
                {
                    tcpClient.Close();
                    clientStream.Close();
                    Stop = false;
                    StreamingVideo = false;
                    return;
                }
                //Simply send the characters "ok" every two seconds
                SendMessage(clientStream, "ok");
                Thread.Sleep(2000);
            }
        }