AS3的Andr​​oid遥控节约声音对SD卡 - 以后访问? [英] as3 android saving remote sounds on sdcard - accessing later?

查看:128
本文介绍了AS3的Andr​​oid遥控节约声音对SD卡 - 以后访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code是非常酷!尝试一下。它在你的用户名为0.007创建一个文件夹并保存名为yahoo.mp3一个MP3。

这也将做到这一点在Android设备上,如果权限设置是否正确。

在它创建了一个文件夹,并保存MP3它将环路直通的文件夹,并得到该文件的路径和文件名。

我的问题是:如何访问并播放声音在Android?它的工作原理在桌面上,你可以,如果你测试,但没有对机器人看到的。任何想法,为什么?

 进口flash.filesystem *。
VAR urlString:字符串=htt​​p://YourWebsite.com/YourSound.mp3;
VAR urlReq:的URLRequest =新的URLRequest(urlString);
VAR urlStream:URLStream =新URLStream();
VAR的FileData:ByteArray的=新的ByteArray();
urlStream.addEventListener(引发Event.COMPLETE,加载);
在URLStream.load(urlReq);

功能加载(事件:事件):无效
{
    urlStream.readBytes(的FileData,0,urlStream.bytesAvailable);
    writeAirFile();
}

功能writeAirFile():无效
{

    var文件:文件= File.userDirectory.resolvePath(007 / Yahoo.mp3);
    VAR FILESTREAM:的FileStream =新的FileStream();
    fileStream.open(文件,FileMode.WRITE);
    fileStream.writeBytes(的FileData,0,fileData.length);
    fileStream.close();
    追踪(文件被写入。);

    VAR桌面:文件= File.userDirectory.resolvePath(0);
    var中的文件:阵列= desktop.getDirectoryListing();
    对于(VAR我:UINT = 0; I< files.length;我++)
    {
        跟踪(文件[I] .nativePath); //获取的文件的路径
        跟踪(文件[我]。名称); //获取名称


        VAR为mySound:声音=新的声音();
        VAR myChannel:的SoundChannel =新的SoundChannel();
        VAR lastPosition:数= 0;
        mySound.load(新的URLRequest(文件[0] .nativePath));
        myChannel = mySound.play();

    }


}
 

解决方案

文件:// < ------- 答案

明白了!需要进入SD卡在Android手机中的文件路径必须以文件://

如果您要加载在手机中的声音会是这样的。这是一个需要重要防线。我会后低于满code。

  mySound.load(新的URLRequest(文件://mnt/sdcard/AnyFolder/YourSound.mp3));
 

由于我是用上面获得特定文件夹中的所有文件的循环,这是在上面的例子中为我工作的code。

  mySound.load(新的URLRequest(文件://+文件[0] .nativePath));
 

FULL code加载和播放声音开DROID

  VAR为mySound:声音=新的声音();
VAR myChannel:的SoundChannel =新的SoundChannel();
VAR lastPosition:数= 0;
mySound.load(新的URLRequest(文件://mnt/sdcard/AnyFolder/YourSound.mp3));
myChannel = mySound.play();
 

我很努力在寻找这个答案。我希望这可以帮助很多。 请记住+1如果code帮助你。 :)

我爱计算器! :)

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

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

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

MY QUESTION IS: How do you access it and play the sound on Android? It works on the desktop as you can see if you test it But not on the droid. Any ideas why?

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:// <-------The Answer!

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

FULL CODE TO LOAD AND PLAY SOUND ON 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();

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

I love StackOverflow! :)

这篇关于AS3的Andr​​oid遥控节约声音对SD卡 - 以后访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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