2011-07-26 71 views
0

我從網站上的數據流,然後把它放在isolatedStorage到IsolatedstorageStream,我想從網站與MediaElement的播放音樂,「media.setSource()」

,但它不工作,沒有錯誤沒有聲音,怎麼了?

HttpWebResponse reponse = request.EndGetResponse(result) as HttpWebResponse; 
if (reponse.StatusCode == HttpStatusCode.OK) 
{ 

    Stream stream=reponse.GetResponseStream(); 
    SaveMusic(stream, "music"); 
    ReadMusic("music"); 
    Deployment.Current.Dispatcher.BeginInvoke(
     () => 
     { 
      me.AutoPlay = true; 
      me.Volume = 100; 
      me.SetSource(songStream); 
      me.Play(); 
     }); 

}   
+0

請注意,遠程音樂播放實際上不會工作,如果你與Zune播放器連接,見http://blogs.msdn.com/b/katriend/archive/201 0 /26分之10/快速尖端使用最WP-連接效用-代替-的-Zune的客戶端 - 窗口電話7.aspx用於連接該裝置的替代方式。 –

回答

0

假設你savingreading代碼是正確的,你的stream's position可能是在年底。嘗試添加

songStream.Position = 0; 

SetSource(songStream);

試圖以此來保存文件:

using (var fileStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
     var buffer = new byte[1024]; 
     using (var myIsStream = fileStorage.OpenFile("Source\\Music\\" + name + ".mp3", FileMode.CreateNew)) 
     { 
       int bytesRead = 0; 
       while ((bytesRead = stream.Read(buffer, 0, 1024)) > 0) 
       myIsStream.Write(buffer, 0, bytesRead); 
     } 
} 
+0

你們,我將有一個嘗試,感謝,但有anonther問題上的錯誤顯示「不允許操作上IsolatedStorageFileStream」 –

+0

感謝您的時間,我有嘗試,但我沒有工作 –

+0

您可以加入你的'SaveMusic'和'ReadMusic'代碼? – keyboardP

0

好,謝謝keyboardP您的幫助,這裏是我的代碼

protected void SaveMusic(Stream stream,string name) 
{ 

      IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
      if (!fileStorage.DirectoryExists("Source/Music")) 
      { 
       fileStorage.CreateDirectory("Source/Music"); 
      } 
      using (IsolatedStorageFileStream fileStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile("Source\\Music\\" + name + ".mp3", FileMode.Create)) 
      { 
       byte[] bytes = new byte[stream.Length]; 
       stream.Read(bytes, 0, bytes.Length); 
       fileStream.Write(bytes, 0, bytes.Length); 
       fileStream.Flush(); 
      } 

} 
protected void ReadMusic(string name) 
{ 

     using (IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      songStream = null; 
      songStream = new IsolatedStorageFileStream("Source\\Music\\" + name + ".mp3", FileMode.Open, fileStorage);     

     } 

} 
+0

嗨,我已經更新了我的答案與MP3文件保存到獨立存儲的不同方式。嘗試使用該代碼。 – keyboardP