资产文件夹中的XML文件无法访问资源/原材料文件夹 [英] XML file in assets folder cannot access res/raw folder

查看:488
本文介绍了资产文件夹中的XML文件无法访问资源/原材料文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该给一些背景开始。我们即将发布一个非盈利性的HTML5儿童游戏为Android平台。我已经使用Eclipse创建一个APK文件,但没有音频(在比赛的其余工作正常)。我已经试过手机的差距,但没有音频进行游戏。做研究和可能的解决方案日子后,我决定在这里提出的计算器。

I should start by giving some background. We're about to release a non profit html5 children's game for android platforms. I have used eclipse to create an apk file but there is no audio (the rest of the game works fine). I have tried phone gap but there is no audio for the game. After doing days of research and possible solutions, I decided to ask here on stackoverflow.

游戏使用HTML / CSS / JS。

The game uses html/css/js.

在Eclipse项目文件夹结构为:
资产(android_assets) - > WWW-> index.html的,game.xml,JS文件夹(游戏引擎),样式文件夹,文件夹的资产。
子资产文件夹包含 - >音乐文件夹,图片文件夹,文件夹的背景

Project folder structure in Eclipse is: assets(android_assets)->www->index.html, game.xml, js Folder (the game engine), styles Folder, and assets Folder. The sub asset folder contains -> music folder, images folder, and backgrounds folder

错误信息:
index.html文件加载game.xml。该game.xml文件加载的资产文件夹中的所有文件。然而,所有的音乐文件都没有找到logcat中:结果
    无法打开文件/android_asset/www/assets/music/song.mp3。 (无此文件或目录)。我的xml文件的声音通话为:<信源HREF =资产/音乐/ Song.mp3的TYPE =MP3/> 结果
我用的图像和背景当前加载罚款同样的参考结构。当加载来自像www.oursever.com/song.mp3外部URL的音乐。本场比赛是作为能在Android设备上的APK文件运行时播放的歌曲就好了。因此,code是正确的,但在本地文件路径中的APK文件的歌曲是错误的。

Error Message: The index.html file loads the game.xml. The game.xml file loads all the files in the assets folder. However, all music files are not found in logcat:
Failed to open file '/android_asset/www/assets/music/song.mp3.' (No such file or directory). My xml file sound call is: <source href="assets/music/song.mp3" type="mp3" />.
I use this same reference structure with images and backgrounds that are currently loading fine. When loading the music from an external url like www.oursever.com/song.mp3. The game is able to play the song just fine when running as an apk file on an Android device. So the code is right but the local file path to the song in the apk file is wrong.

大量的阅读之后,我了解到,资产文件夹为com pressed并且不建议读取该文件夹的音频文件,而不uncom pressing他们。另一种方法是放置在res /原始文件夹中的MP3文件。我改变我的XML阅读:。不过,我收到未找到该文件同样的错误。我知道在res文件夹项目所采用的标识符。但我不知道我应该把在XML源文件路径来引用歌曲RES /生。我打印出来的文件路径歌曲使用此code:的System.out.println(原路径:+的getString(R.raw.menu));

After much reading, I learned that the assets folder is compressed and it is not recommended to read audio files from that folder without uncompressing them. The alternative is to place the mp3 files in the res/raw folder. I change my xml to read: ''. However, I receive the same error about the file not being found. I know items place in the res folder uses identifiers. But I'm not sure what I should put in the xml source file path to reference the song in res/raw. I printed out the file path to the song by using this code: System.out.println("Raw Path: " + getString(R.raw.menu));

哦,我试了另一种方法,是推动整个应用程序到SD卡。我还收到了找不到文件的错误。

Oh another method I tried, was pushing the entire app to the SDCard. I still received the "cannot find file" error.

应用程序的权限:

 - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 - <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>   
 - <uses-permission android:name="android.permission.INTERNET"/>
 - <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

摘要

本场比赛正常工作我们本地网络服务器的所有资产。当试图创建一个使用Eclipse和PhoneGap的选项的APK文件产生游戏没有音讯。我读了资产的文件夹中有每个文件1 MB的限制,这样的另一个原因是,我试图使用RES /原始文件夹中。是从发布这个非营利的儿童游戏阻止我们唯一的问题是,我无法找到那里的音乐文件位于apk文件中。我已经探索了apk文件内容,它表明Song.mp3的是里面RES /生/文件夹。然而,Android SDK中指出它不是。没有人有任何想法?

The game works fine on our local webserver with all assets. When trying to create an apk file using Eclipse and Phonegap options produces the game with no audio. I read that the assets folder has a 1 mb limit per file so that is another reason why I am attempting to use res/raw folder. The only issue that is stopping us from publishing this non profit children's game is that I cannot find where the music file is located at within the apk file. I have explored the apk file contents and it shows that song.mp3 is inside res/raw/ folder. However the Android SDK states it not. Does anyone have any ideas?

感谢您四个时间,

它的我第一次在这里发帖,所以让我知道如果有什么是混乱的。

Its my first time posting here so let me know if anything is confusing.

更新1
我尝试另一种想法,试图从SD卡读取歌曲,当我尝试这样做,我收到一个权限被拒绝错误(所以也没找到该文件)。即使我有READ_EXTERNAL_STORAG​​E权限设置,我的应用程序正在使用MP3文件拒绝。所以,我想从原目录拷贝歌曲,使得SD卡上的一个新的文件夹,通​​过使用这个链接将在新的文件夹中:
如何Raw文件复制到SD卡

在使用此解决方案是永远不会创建的文件夹和文件,也从未被复制。我也不能将其安装到我的手机后,发现我的应用程序。我检查了内部存储 - >文件夹SD卡并检查COM文件夹。我还检查我的外部存储 - > SD卡的com.mycompany文件夹及其不是他们无论是。我们的测试手机运行的是Android 4.1.2。

When using this solution the folder is never created and the file is never copied either. I also cannot find my app after installing it to my phone. I checked the internal storage->sdcard folder and examine the com folders. I also checked my external storage->sdcard for the com.mycompany folder and its not their either. Our test phone is running Android 4.1.2.

更新2
我尝试了示例项目的建议。我收到无法打开文件'android.resource://com.mycompany/raw/song.mp3'的错误。 (无此文件或目录)。 Song.mp3的坐落在res /原始文件夹中。我尝试另一种想法,试图从SD卡读取歌曲,当我尝试这样做,我收到一个权限被拒绝错误(所以也没找到该文件)。即使我有READ_EXTERNAL_STORAG​​E权限集。

Update 2 I tried the suggestion for the sample project ''. I receive the error Failed to open file 'android.resource://com.mycompany/raw/song.mp3'. (No such file or directory). Song.mp3 is located in the res/raw folder. I tried an alternate idea by trying to read the song from the SD Card, when I tried this I received a permission denied error (so it did find the file). Even though I have READ_EXTERNAL_STORAGE permissions set.

更新3
我从头工作的一个空白项目。我用了previous项目的教程是: https://www.youtube.com/手表?v = QRa4yMjoI7c
我会更新这个帖子下周一,谢谢安德鲁和其他人,至少看到这个帖子。

Update 3 I'm working on a blank project again from scratch. The tutorial I used for the previous project is: https://www.youtube.com/watch?v=QRa4yMjoI7c I'll update this post next Monday, thank you Andrew and anyone else that at least viewed this post.

更新4
我做了,我在这里上传了示例项目:
http://tinyurl.com/p7s5w2v
转到文件然后下载。
该项目是非常小的,但你可以看到,我把menu.mp3文件中的原始/ res目录和android.resource://com.mycompany/raw/menu.mp3'是无法找到这首歌的时候叫在fisher.xml。这首歌正确播放我们的网络服务器和本地服务器。但在Android设备或仿真器上运行时menu.mp3无法找到。我总是告诉xml文件加载所有从我们的网络服务器游戏中的音频文件,但这将是缓慢的。

Update 4 I have made a sample project that I have uploaded here: http://tinyurl.com/p7s5w2v Go to file then download. The project is extremely small but you can see that I put the menu.mp3 file in the raw/res directory and that 'android.resource://com.mycompany/raw/menu.mp3' is unable to find the song when called in 'fisher.xml'. The song plays correctly on our webserver and our local server. But menu.mp3 cannot be found when running on an android device or emulator. I can always tell the xml file to load all the audio files for the game from our webserver but this will be slow.

更新5
目前的尝试次数:

Update 5 Current Tries:

source href="android.resource://com.brg.example/raw/menu" file not found
source href="sdcard/menu.mp3" permission denied on sdcard (app has read access)
source href="storage/sdcard0/menu.mp3" permission denied
source href="file:///assets/music/menu.mp3" file not found

清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.brg.example"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.brg.example.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

更新6
我决定定居在使用url从远程服务器加载的媒体文件。我最初以为一个HTML项目转换为音频的机器人的WebView会少耗时比其它平台。我错了这一点。我们可能会在将来再次重温的Andr​​oid。我们支付了他们的售后服务PhoneGap的支持团队已基本沉默。我感谢大家,决定一瞥在此张贴。

Update 6 I have decided to settle on loading the media files from a remote server using a url. I initially thought converting a html project to an android webview with audio would be less time consuming than other platforms. I was mistaken with this. We may revisit Android again in the future. PhoneGap support team has been basically silent after we paid for their service. I thanked everyone that decided to glance at this posting.

推荐答案

我刚刚也有类似的问题 - 对我来说是关键的部分是省略的媒体文件的扩展名: android.resource ://com.mycompany/raw/song

I've just had a similar problem -- for me the key part was omitting the extension of the media file: android.resource://com.mycompany/raw/song

这篇关于资产文件夹中的XML文件无法访问资源/原材料文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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