Exemple #1
0
        public void Stop()
        {
            if (tsStream != null)
            {
                tsStream.Stop();
                tsStream = null;
            }

            decoder.Pause();
            Initialize();
        }
Exemple #2
0
        public int Open(string url, StreamType streamType = StreamType.TORRENT, bool isMagnetLink = true)
        {
            this.streamType = streamType;

            status = Status.OPENING;
            Initialize();

            if (streamType == StreamType.FILE)
            {
                fsStream = new FileStream(url, FileMode.Open, FileAccess.Read);
                fileSize = fsStream.Length;

                Torrent torrent = new Torrent("whatever");
                torrent.file         = new Torrent.TorrentFile();
                torrent.file.paths   = new List <string>();
                torrent.file.lengths = new List <long>();

                torrent.file.paths.Add("MediaFile1.mp4");
                torrent.file.paths.Add("MediaFile2.mp4");
                torrent.file.lengths.Add(123123894);
                torrent.file.lengths.Add(123123897);

                MetadataReceived(torrent);

                status = Status.OPENED;
            }
            else if (streamType == StreamType.TORRENT)
            {
                if (tsStream != null)
                {
                    tsStream.Dispose();
                }

                TorSwarm.OptionsStruct opt = TorSwarm.GetDefaultsOptions();
                opt.FocusPointCompleted = FocusPointCompleted;
                opt.TorrentCallback     = MetadataReceived;
                opt.StatsCallback       = Stats;
                opt.PieceTimeout        = 4300;
                //opt.LogStats            = true;
                //opt.Verbosity           = 1;

                try
                {
                    if (isMagnetLink)
                    {
                        tsStream = new TorSwarm(new Uri(url), opt);
                    }
                    else
                    {
                        tsStream = new TorSwarm(url, opt);
                    }
                } catch (Exception e) { Log($"[MS] TorSwarm Failed Opening Url {e.Message}\r\n{e.StackTrace}"); Initialize(); status = Status.FAILED; return(-1); }

                try
                {
                    tsStream.Start();
                } catch (Exception e) { Log($"[MS] TorSwarm is Dead, What should I Do? {e.Message}\r\n{e.StackTrace}"); Initialize(); status = Status.FAILED; return(-1); }

                status = Status.OPENED;
            }

            return(0);
        }