Ejemplo n.º 1
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(this, new BitSwarm.MetadataReceivedArgs(torrent));

                status = Status.OPENED;
            }
            else if (streamType == StreamType.TORRENT)
            {
                BitSwarm.OptionsStruct opt = BitSwarm.GetDefaultsOptions();
                opt.PieceTimeout = 4300;
                //opt.LogStats            = true;
                //opt.Verbosity           = 2;

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

                tsStream.MetadataReceived += MetadataReceived;
                tsStream.StatsUpdated     += Stats;

                tsStream.Start();
                sortedPaths = null;
                status      = Status.OPENED;
            }

            return(0);
        }