Xamarin C#的Andr​​oid和解析 - 下载parseFile一个内部的parseObject [英] Xamarin C# android and PARSE - Downloading a parseFile inside a parseObject

查看:164
本文介绍了Xamarin C#的Andr​​oid和解析 - 下载parseFile一个内部的parseObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我previously发了一个帖子,询问如何发送.3GPP音频文件到这里的解析云:
<一href=\"https://stackoverflow.com/questions/27259432/xamarin-c-sharp-android-converting-3gpp-audio-to-bytes-sending-to-parseobje\">Xamarin C#的Andr​​oid - .3GPP音频转换为字节&安培;发送给的parseObject

I previously made a post asking how to send a .3gpp audio file up to the parse cloud here: Xamarin C# Android - converting .3gpp audio to bytes & sending to parseObject

我已经设法成功地做到这一点,解析的数据管理器,我可以点击该文件的链接,播放从Android设备发送成功的声音。
这里的code的数据上传到云:

I have managed to do this successfully, on parse's data manager, I can click the file's link and play the sound sent from my android device successfully. Here's the code for uploading the data to the cloud:

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。
这个对象有两个孩子:
用户的用户名-The谁上传的文件(字符串)
-The parseFile称为文件(它具有以下两个孩子)
--- SaveTheFile(,添加了一个包含音频文件的名称字符串用户,与.3GPP扩展输入的结尾,例如myAudioFile.3gpp
---数据(这包含音频文件的字节)

So as you can see, I'm sending a ParseObject called "AudioWithData". This object contains two children: -The username of the user who uploaded the file (string) -The parseFile called "file" (which has the following two children) ---SaveTheFile (A string containing the name of the audio file, input by the user, with the .3gpp extension added on the end, for example "myAudioFile.3gpp" ---data (this contains the bytes of the audio file)

我需要能够将文件下载到自己的Andr​​oid设备,并通过MediaPlayer对象进行播放。

I need to be able to download the file onto my android device, and play it through a mediaplayer object.

我检查解析网站上的文档了,但我还没有成功地做到这一点:
(此处原谅我的伪查询语法)
SELECT(音频文件)(中的parseObject)WHERE(用户名=当前用户)
然后我,最终希望所有这些文件放到一个列表视图,当用户点击该文件,其播放音频。

I've checked over the documentation on the parse website, but I haven't managed to do this: (excuse my pseudo querying syntax here) SELECT (audio files) FROM (the parseObject) WHERE (the username = current user) I then, eventually, want to place all of these files into a listview, and when the user clicks the file, it plays the audio.

我试过了,但之后我真的不知道我用它做...

I've tried the following but I don't really know what I'm doing with it...

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 (); 
}

任何帮助将不胜AP preCIATED!即使是在正确方向上的一点将是巨大的!
谢谢!

Any help would be GREATLY APPRECIATED! Even a point in the right direction would be great! Thanks!

编辑 -

我真的开始在随后的行查询错误
(我不能发表图片,因为我的名气 - 我失去了进入我的主要StackOverflow的帐户:/)
链接在这里图片:

I'm actually getting a query error on the following lines (I can't post images because of my reputation - I lost access to my main stackOverflow account :/ ) Links to images here:

第一个错误: http://i.stack.imgur.com/PZBJr.png
  第二个错误:
http://i.stack.imgur.com/UkHvX.png
有任何想法吗?解析文档是模糊的这个问题。

first error: http://i.stack.imgur.com/PZBJr.png second error: http://i.stack.imgur.com/UkHvX.png Any ideas? The parse documentation is vague about this.

推荐答案

这行会返回结果的集合

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

您可能需要通过他们与的foreach 来重复,还是只挑选第一个

you either need to iterate through them with foreach, or just pick the first one

// 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

}

这篇关于Xamarin C#的Andr​​oid和解析 - 下载parseFile一个内部的parseObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆