Exemplo n.º 1
0
        private void Init()
        {
            IStreamableFileService service = ((IStreamableFileFactory)ScopeUtils.GetScopeService(this._scope, typeof(IStreamableFileFactory))).GetService(this._file);

            if (service == null)
            {
                log.Error("No service found for " + this._file.FullName);
            }
            else
            {
                this._reader = service.GetStreamableFile(this._file).GetReader();
                if (this._start > 0)
                {
                    this.Seek(this._start);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns stream length. Method added to get flv player to work.
        /// </summary>
        /// <param name="name">Stream name.</param>
        /// <returns>Returns the length of a stream, in seconds.</returns>
        public double getStreamLength(string name)
        {
            double           duration = 0;
            IProviderService provider = ScopeUtils.GetScopeService(this.Scope, typeof(IProviderService)) as IProviderService;
            FileInfo         file     = provider.GetVODProviderFile(this.Scope, name);

            if (file != null)
            {
                IStreamableFileFactory factory = (IStreamableFileFactory)ScopeUtils.GetScopeService(this.Scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory;
                IStreamableFileService service = factory.GetService(file);
                if (service != null)
                {
                    ITagReader reader = null;
                    try
                    {
                        IStreamableFile streamFile = service.GetStreamableFile(file);
                        reader   = streamFile.GetReader();
                        duration = (double)reader.Duration / 1000;
                    }
                    catch (IOException ex)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error(string.Format("Error reading stream file {0}. {1}", file.FullName, ex.Message));
                        }
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error(string.Format("No service found for {0}", file.FullName));
                    }
                }
                file = null;
            }
            return(duration);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes file provider. Creates streamable file factory and service, seeks to start position.
        /// </summary>
        private void Init()
        {
            IStreamableFileFactory factory = (IStreamableFileFactory)ScopeUtils.GetScopeService(_scope, typeof(IStreamableFileFactory));
            IStreamableFileService service = factory.GetService(_file);

            if (service == null)
            {
                log.Error("No service found for " + _file.FullName);
                return;
            }
            IStreamableFile streamFile = service.GetStreamableFile(_file);

            _reader = streamFile.GetReader();
            if (_start > 0)
            {
                Seek(_start);
            }
        }
Exemplo n.º 4
0
        private void Init()
        {
            IStreamableFileFactory factory = ScopeUtils.GetScopeService(_scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory;
            string directory = Path.GetDirectoryName(_file.FullName);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            if (!_file.Exists)
            {
                // Maybe the (previously existing) file has been deleted
                using (FileStream fs = _file.Create()){}
            }

            /*
             * else if (_file.IsReadOnly)
             * {
             * throw new IOException("The file is read-only");
             * }
             */
            IStreamableFileService service = factory.GetService(_file);
            IStreamableFile        flv     = service.GetStreamableFile(_file);

            if (_mode == null || _mode.Equals(Constants.ClientStreamModeRecord))
            {
                _writer = flv.GetWriter();
            }
            else if (_mode.Equals(Constants.ClientStreamModeAppend))
            {
                _writer = flv.GetAppendWriter();
            }
            else
            {
                throw new NotSupportedException("Illegal mode type: " + _mode);
            }
        }