2014-12-05 16 views
0

裏面我之前發了一個帖子,詢問如何發送.3GPP音頻文件到解析雲在這裏: Xamarin C# Android - converting .3gpp audio to bytes & sending to parseObjectXamarin C#的Android和解析 - 下載parseFile一個的parseObject

我已經設法成功地做到這一點,在解析的數據管理器上,我可以點擊文件的鏈接併成功播放從我的android設備發送的聲音。 下面是數據上傳到雲代碼:

async Task sendToCloud(string filename) 
    { 

     ParseClient.Initialize ("Censored Key", "Censored Key"); 
     string LoadPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); 
     string savetheFile = sName + ".3gpp"; 
     string tempUserName; 
     LoadPath += savetheFile; 
     Console.WriteLine ("loadPath: " + LoadPath); 
     try 
     { 

      byte[] data = File.ReadAllBytes(LoadPath); 
      ParseFile file = new ParseFile(savetheFile, data); 
      await file.SaveAsync(); 

      var auidoParseObject = new ParseObject("AudioWithData"); 
      //Console.WriteLine(ParseUser.getUserName()); 
      if (ParseUser.CurrentUser != null) 
      { 
       tempUserName = ParseUser.CurrentUser.Username.ToString(); 
      } 

      else{ 
       tempUserName = "Anonymous"; 
      } 
      //tempUserName = ParseUser.CurrentUser.Username.ToString(); 
      Console.WriteLine("PARSE USERNAME: " + tempUserName); 

       auidoParseObject["userName"] = tempUserName; 


      auidoParseObject["userName"] = tempUserName; 
      auidoParseObject["file"] = file; 
      await auidoParseObject.SaveAsync(); 

     } 

     catch (Exception e) 
     { 
      Console.WriteLine("Failed to await audio object! {0}" + e); 
     } 

    } 

因此,大家可以看到,我送了一個名爲「AudioWithData」的parseObject。 此對象包含兩個子項: - 上傳文件的用戶名(字符串) -parseFile被稱爲「文件」(其具有以下兩個子項) --- SaveTheFile(包含名稱的字符串音頻文件,由用戶輸入,並在末尾添加.3gpp擴展名,例如「myAudioFile.3gpp」 ---數據(包含音頻文件的字節)

我需要能夠將文件下載到我的Android設備上,並通過mediaplayer對象播放。

我檢查瞭解析網站上的文檔,但我沒有設法執行此操作: (請原諒我的僞查詢語法) SELECT(音頻文件)FROM(parseObject)WHERE(用戶名=當前用戶) 然後,我最終希望將所有這些文件放入列表視圖中,並且當用戶單擊該文件,它播放音頻。

我試過以下,但我真的不知道我用它做...

async Task RetrieveSound(string filename) 
    { 
     ParseClient.Initialize ("Censored key", "Censored key"); 
     Console.WriteLine ("Hit RetrieveSound, filename = " + filename); 
     string username; 
     var auidoParseObject = new ParseObject("AudioWithData"); 
     if (ParseUser.CurrentUser != null) { 
      username = ParseUser.CurrentUser.Username.ToString(); 
     } else { 
      username = "Anonymous"; 
     } 
     string cloudFileName; 
     Console.WriteLine ("username set to: " + username); 


     var HoldThefile = auidoParseObject.Get<ParseFile>("audio"); 

     //fgher 
     var query = from audioParseObject in ParseObject.GetQuery("userName") 
       where audioParseObject.Get<String>("userName") == username 
      select file; 
     IEnumerable<ParseFile> results = await query.FindAsync(); 

     Console.WriteLine ("passed the query"); 
     //wfojh 

     byte[] data = await new HttpClient().GetByteArrayAsync(results.Url); 
     Console.WriteLine ("putting in player..."); 
     _player.SetDataSourceAsync (data); 
     _player.Prepare; 
     _player.Start(); 
} 

任何幫助將不勝感激!即使在正確的方向上的一個點將是偉大的! 謝謝!

EDIT--

我真的開始在隨後的行 查詢錯誤(我不能發表,因爲我的名氣圖片 - 我失去了進入我的主要StackOverflow的帳戶:/) 鏈接圖片在這裏:

第一個錯誤:http://i.stack.imgur.com/PZBJr.png 第二個錯誤:http://i.stack.imgur.com/UkHvX.png 任何想法?解析文檔對此很模糊。

回答

0

此行會返回結果

IEnumerable<ParseFile> results = await query.FindAsync(); 

的集合,您可能需要通過他們與foreach迭代,還是隻挑選的第一個

// for testing, just pick the first one 
if (results.Count > 0) { 

    var result = results[0]; 

    byte[] data = await new HttpClient().GetByteArrayAsync(result.Url); 

    File.WriteAllBytes(some_path_to_a_temp_file, data); 

    // at this point, you can just initialize your player with the audio file path and play as normal 

} 
+0

我給它當一試GET我的筆記本電腦。謝謝 – 2014-12-07 18:40:15

+0

嗨傑森,感謝您的迴應,但是我實際上得到與查詢本身的錯誤,請參閱我原來的職位底部我的編輯。我已將錯誤快照成圖像,但是,由於我的聲望點,我無法直接在此處發佈圖像。 – 2014-12-09 21:55:52