Exemplo n.º 1
0
        /// <summary>
        /// Method: Initialize 
        /// Initialize the cache
        /// Parameter: container is a string defining the folder name where the cache will be stored on disk under folder
        /// \Users\<UserName>\AppData\Local\Packages\<PackageID>\LocalState
        /// Parameter: bDownloadToGo if true DownloadToGo scenario (offline playback), if false ProgressiveDownload scenario
        /// Parameter: maxDownloadSession maximum number of simultaneous download sessions
        /// Parameter: maxDownloadSession maximum number of simultaneous download sessions
        /// Parameter: maxMemoryBufferSizePerSession maximum buffer size per session, when the size if over this value, the chunks will be saved on disk and freed from memory.
        /// Parameter: maxDownloadedAssets maximum number of asset on disk
        /// Parameter: maxError maximum number of http error while downloading the chunks associated with an asset. When this value is reached the download thread will be cancelled
        /// Parameter: bAutoStartDownload if true after a resume the cache will start automatically the download 
        /// </summary>
        public IAsyncOperation<bool> Initialize(string container, uint maxDownloadSession, ulong maxMemoryBufferSizePerSession, uint maxDownloadedAssets, uint maxError, bool bAutoStartDownload)
        {
            return Task.Run<bool>(async () =>
            {
                if (ManifestCacheList != null)
                    Uninitialize();
                Container = container;


                MaxError = maxError;
                MaxMemoryBufferSizePerSession = maxMemoryBufferSizePerSession;
                MaxDownloadSessions = maxDownloadSession;
                MaxDownloadedAssets = maxDownloadedAssets;
                AutoStartDownload = bAutoStartDownload;

                // SMOOTH
                // Init Adaptative Manager
                AdaptiveSrcManager = AdaptiveSourceManager.GetDefault();
                AdaptiveSrcManager.SetDownloaderPlugin(this);
                AdaptiveSrcManager.AdaptiveSourceOpenedEvent += AdaptiveSrcManager_AdaptiveSourceOpenedEvent;
                AdaptiveSrcManager.AdaptiveSourceClosedEvent += AdaptiveSrcManager_AdaptiveSourceClosedEvent;


                // SMOOTH
                // Init SMOOTH Manager
                SmoothStreamingManager = Microsoft.Media.AdaptiveStreaming.AdaptiveSourceManager.GetDefault() as Microsoft.Media.AdaptiveStreaming.AdaptiveSourceManager;
                Extension = new Windows.Media.MediaExtensionManager();
                if ((SmoothStreamingManager != null) &&
                    (Extension != null))
                {
                    Windows.Foundation.Collections.PropertySet ssps = new Windows.Foundation.Collections.PropertySet();
                    ssps["{A5CE1DE8-1D00-427B-ACEF-FB9A3C93DE2D}"] = SmoothStreamingManager;


                    Extension.RegisterByteStreamHandler("Microsoft.Media.AdaptiveStreaming.SmoothByteStreamHandler", ".ism", "text/xml", ssps);
                    Extension.RegisterByteStreamHandler("Microsoft.Media.AdaptiveStreaming.SmoothByteStreamHandler", ".ism", "application/vnd.ms-sstr+xml", ssps);
                    Extension.RegisterByteStreamHandler("Microsoft.Media.AdaptiveStreaming.SmoothByteStreamHandler", ".isml", "text/xml", ssps);
                    Extension.RegisterByteStreamHandler("Microsoft.Media.AdaptiveStreaming.SmoothByteStreamHandler", ".isml", "application/vnd.ms-sstr+xml", ssps);


                    Extension.RegisterSchemeHandler("Microsoft.Media.AdaptiveStreaming.SmoothSchemeHandler", "ms-sstr:", ssps);
                    Extension.RegisterSchemeHandler("Microsoft.Media.AdaptiveStreaming.SmoothSchemeHandler", "ms-sstrs:", ssps);

                    SmoothStreamingManager.ManifestReadyEvent += SmoothStreamingManager_ManifestReadyEvent;
                    SmoothStreamingManager.SetDownloaderPlugin(this);
                }

                if (diskCache == null)
                {
                    diskCache = new DiskCache();
                    if (diskCache != null)
                    {
                        bool bResult = false;
                        bResult = await diskCache.Initialize(Container);
                        if (bResult != true)
                        {
                            System.Diagnostics.Debug.WriteLine("Can't initialize DiskCache");
                            return false;
                        }
                    }
                }
                if (ManifestCacheList == null)
                    ManifestCacheList = new ConcurrentDictionary<Uri, ManifestCache>();
                if (ManifestCacheList != null)
                    IsInitialized = true;
                return IsInitialized;
            }).AsAsyncOperation<bool>();
        }
Exemplo n.º 2
0
 /// <summary>
 /// SetDiskCache
 /// Associate a Disk cache with the manifest.
 /// The DiskCache will be used to store the manifest on disk
 /// </summary>
 /// <param name="cache">DiskCache</param>
 /// <returns>true if successful</returns>
 public bool SetDiskCache(DiskCache cache)
 {
     if (cache != null)
     {
         DiskCache = cache;
         return true;
     }
     return false;
 }