开发落网电台windows phone 8应用的计划(5)

这两天把网络的事情搞了一下,由于并没有api可以使用,所以我是选择下载了网站的html代码用正则表达式找出资源链接。

但是到现在也不知道是不是出于网络的原因,后台的OpenReadAsyncComplete事件一直没有响应。

我用的是webClient类,代码如下:

问题代码出现在最后一部分。。

  1 using System;
  2 using System.Diagnostics;
  3 using System.Windows;
  4 using Microsoft.Phone.BackgroundAudio;
  5 using System.Collections.Generic;
  6 using System.Text.RegularExpressions;
  7 using System.Threading;
  8 using System.Net;
  9 using System.IO;
 10 namespace LuooAudioPlayerAgent
 11 {
 12   
228         public static  void GetMaxAlbumNumber()
229         {
230             //GetMaxAlbumNumber
231             WebClient origionWebClient=new WebClient();
232             //origionWebClient.AllowReadStreamBuffering=false;
233             origionWebClient.OpenReadAsync(new Uri("http://www.luoo.net" , UriKind.Absolute));
234             origionWebClient.OpenReadCompleted+=origionWebClient_OpenReadCompleted; //。。。。这是事件
235             //set currentAlbumNumber
236         }
237 
238         static void origionWebClient_OpenReadCompleted( object sender , OpenReadCompletedEventArgs e ) //这里就是没有消息。。
239         {
240             StreamReader sR=new StreamReader(e.Result);
241             string html=sR.ReadToEnd();
242             //GetMaxAlbumNumber
243             string pattern=@"vol. [0-9]+";
244             MatchCollection matches=Regex.Matches(@html , pattern);
245             string temp=matches[0].ToString().Split(' ')[1];
246             maxAlbumNumber=int.Parse(temp);
247             //set currentAlbumNumber
248             currentAlbumNumber=maxAlbumNumber;
249             //set isFinished
250             isFinished=true;
251         }
252     }
253 }

如果园友看了之后有知道其中原因的,欢迎指教。。。。

mail:tian_feng_bo@live.com

 

posted on 2014-03-17 22:31  uestc小田  阅读(198)  评论(0编辑  收藏  举报

导航