예제 #1
0
        public void Play(bool _onlyLocal = true)
        {
            if (CurrentState == State.Playing)
            {
                return;
            }

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            //if (onlyLocal != _onlyLocal)
            //    CloseSenders();

            if (CurrentState == State.Paused)
            {
                Resume();
            }
            else
            {
                resetTimeOffsetRequired = true;

                onlyLocal    = _onlyLocal;
                cancelSource = new CancellationTokenSource();
                cancelToken  = cancelSource.Token;
                runningJob   = new Task(() => RunReaderSenderProcessCallback(filePath, idxFilePath, cancelToken), cancelToken, TaskCreationOptions.None);
                CurrentState = State.Playing;

                // Create Senders
                foreach (PlayPeerInfo p in udpSenders.Values)
                {
                    var u = new UDPSender(p.ID, p.IP, p.Port, false);
                    u.DataRateEvent += OnDataRate;
                    u.Start();

                    p.commsLink = u;
                }

                // Start Timer
                eventTimer = new Timer(OnEventTimer, null, 0, 1000);

                runningJob.Start();

                StatusEvent?.Invoke(CurrentState);
            }
        }