/// <summary> /// This function sets up the background request for the image /// </summary> /// <param name="index"></param> protected override void OnRequestSlowData(int index) { //if this request has already been made once if (_pendingItemRequest.ContainsKey(index)) { //cancel the request return; } //If this virtual list does not have a proper query if (Query == "") { //don't try to get an image return; } //add this index to the pendingItemRequest list so that we know this has already been requested _pendingItemRequest[index] = index; //create a new slowdata Request item. SlowDataItem slowData = new SlowDataItem(); //set the slowdata index to match index requested slowData.Index = index; //Read the path of the image url from the relevant video item. slowData.PicturePath = ((VideoItem)this[slowData.Index]).Format.CoverArtLargeUri; //schedule this process to run on a worker thread Microsoft.MediaCenter.UI.Application.DeferredInvokeOnWorkerThread(GetVideoImage, ProcessSlowData, slowData); }
/// <summary> /// This function goes and gets the image /// </summary> /// <param name="args"></param> private static void GetVideoImage(object args) { // Heavy operation: get video information from amazon. ThreadPriority priority = Thread.CurrentThread.Priority; try { Thread.CurrentThread.Priority = ThreadPriority.Lowest; SlowDataItem slowData = (SlowDataItem)args; if (slowData.PicturePath == "") { return; } try { //actually go and get the image. slowData.TitleImage = new Image(slowData.PicturePath); } catch (Exception e) { //not sure what we can do in this case } } finally { Thread.CurrentThread.Priority = priority; } }
/// <summary> /// This function updates the relevant video item with the retrieved image. /// </summary> /// <param name="args"></param> private void ProcessSlowData(object args) { SlowDataItem slowData = (SlowDataItem)args; _pendingItemRequest.Remove(slowData.Index); if (IsDisposed || !IsItemAvailable(slowData.Index)) { return; } //go and get the relevant video item VideoItem v = (VideoItem)this[slowData.Index]; //set the image to be the retrieved image v.Image = slowData.TitleImage; }