as3 android 在 sdcard 上保存远程声音 - 稍后访问? [英] as3 android saving remote sounds on sdcard - accessing later?

查看:10
本文介绍了as3 android 在 sdcard 上保存远程声音 - 稍后访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码很酷!试试看.它会在您的用户中创建一个名为 .007 的文件夹并保存一个名为 yahoo.mp3 的 mp3.

This code is way cool! Try it. It creates a folder in your user called .007 and saves an mp3 called yahoo.mp3.

如果权限设置正确,它也可以在 android 设备上执行此操作.

It will also do it on an android device if permissions are set correctly.

一旦它创建了一个文件夹并保存了 mp3,它将遍历该文件夹并获取文件路径和文件名.

Once it creates a folder and saves the mp3 it will loop thru the folder and get the file path and the file name.

我的问题是:您如何访问它并在 Android 上播放声音?它在桌面上工作,你可以看到如果你测试它但不是在机器人上.有什么想法吗?

import flash.filesystem.*;
var urlString:String = "http://YourWebsite.com/YourSound.mp3";
var urlReq:URLRequest = new URLRequest(urlString);
var urlStream:URLStream = new URLStream();
var fileData:ByteArray = new ByteArray();
urlStream.addEventListener(Event.COMPLETE, loaded);
urlStream.load(urlReq);

function loaded(event:Event):void
{
    urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);
    writeAirFile();
}

function writeAirFile():void
{

    var file:File = File.userDirectory.resolvePath(".007/Yahoo.mp3");
    var fileStream:FileStream = new FileStream();
    fileStream.open(file, FileMode.WRITE);
    fileStream.writeBytes(fileData, 0, fileData.length);
    fileStream.close();
    trace("The file is written.");

    var desktop:File = File.userDirectory.resolvePath(".0");
    var files:Array = desktop.getDirectoryListing();
    for (var i:uint = 0; i < files.length; i++)
    {
        trace(files[i].nativePath);// gets the path of the files
        trace(files[i].name);// gets the name


        var mySound:Sound = new Sound();
        var myChannel:SoundChannel = new SoundChannel();
        var lastPosition:Number = 0;
        mySound.load(new URLRequest(files[0].nativePath));
        myChannel = mySound.play();

    }


}

推荐答案

file:// <-------答案!

file:// <-------The Answer!

明白了!在 Android 手机上访问sdcard"所需的文件路径必须以:file://

Got it! The file path needed to access the "sdcard" on a Android phone must begin with: file://

如果您想从手机加载声音,它看起来像这样.这是需要的一条重要线路.我将在下面发布完整的代码.

If you want to load a sound from your phone it would look like this. Here is the one important line needed. I will post full code below.

mySound.load(new URLRequest("file://mnt/sdcard/AnyFolder/YourSound.mp3"));

由于我使用了上面的循环来获取特定文件夹中的所有文件,因此在上面的示例中对我有用的代码.

Since I was using a loop above getting all the files in a particular folder this is the code that worked for me in the example above.

mySound.load(new URLRequest("file://"+files[0].nativePath));

在 DROID 上加载和播放声音的完整代码

var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
mySound.load(new URLRequest("file://mnt/sdcard/AnyFolder/YourSound.mp3"));
myChannel = mySound.play();

我非常努力地找到了这个答案.我希望这对很多人有帮助.如果此代码对您有帮助,请记得 +1.:)

I worked very hard on to find this answer. I hope this helps many. Please remember to +1 if this code has helped you. :)

我喜欢 StackOverflow!:)

这篇关于as3 android 在 sdcard 上保存远程声音 - 稍后访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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