Ejemplo n.º 1
0
        private void Init()
        {
            IStreamableFileFactory scopeService = ScopeUtils.GetScopeService(this._scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory;
            string directoryName = Path.GetDirectoryName(this._file.FullName);

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
            if (!this._file.Exists)
            {
                using (this._file.Create())
                {
                }
            }
            IStreamableFile streamableFile = scopeService.GetService(this._file).GetStreamableFile(this._file);

            if ((this._mode == null) || this._mode.Equals("record"))
            {
                this._writer = streamableFile.GetWriter();
            }
            else
            {
                if (!this._mode.Equals("append"))
                {
                    throw new NotSupportedException("Illegal mode type: " + this._mode);
                }
                this._writer = streamableFile.GetAppendWriter();
            }
        }
Ejemplo 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);
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }