EzDevInfo.com

Assets

An ultra-simple-to-use assets management library for PHP

Route helpers in asset pipeline

using Rails 3.1.0.rc4, I'm trying to access a route helper in a javascript file (event.js.erb in this case) and it seems like they are not loaded at that moment. When requesting the merged /assets/application.js file, I get:

throw Error("NameError: undefined local variable or method `events_path' for #<#<Class:0x00000001580010>:0x00000003191510>\n  (in /<...>/app/assets/javascripts/event.js.erb)")

Any idea how to access the route helper in there?


Source: (StackOverflow)

How to make an iOS asset bundle?

I saw a custom asset bundle in an iOS project I evaluated, so at least I know it's possible.

My issue is that I'm using a CATiledLayer with about 22,000 tiles for a given image and it takes a very long time to compile (half an hour clean build, 5-10 minutes for regular build). So, I want to take all of the images and make a custom bundle to make it portable and hopefully not recompile into the app bundle each time.

How do I go about this? I checked the docs, but didn't see an explanation on how to actually create the bundle.


Source: (StackOverflow)

Advertisements

Android: How to copy files from 'assets' folder to sdcard?

I have a few files in the assets folder. I need to copy all of them to a folder say /sdcard/folder. I want to do this from within a thread. How do I do it?


Source: (StackOverflow)

Play audio file from the assets directory

I have the following code:

AssetFileDescriptor afd = getAssets().openFd("AudioFile.mp3");
player = new MediaPlayer();
player.setDataSource(afd.getFileDescriptor());
player.prepare();
player.start();

The problem is that, when I run this code, it starts playing all the audio files in the assets directory, in alphabetical order instead of just playing the audio file I requested. What am I doing wrong? Is there a better way to play audio files from the assets directory?

Follow-up question: Is there a difference between keeping audio files in the assets directory and keeping them in the res/raw directory? Besides the fact that they don't get ids if they are in the assets directory. If I move the audio files to the res/raw folder then I have a problem with reusing MediaPlayers because there is no id parameter for setDataSource(). I can't find a good guideline for handling this kind of problem.


Source: (StackOverflow)

Rails 3.1 asset pipeline: how to load controller-specific scripts?

If I generate a new controller in Rails 3.1, also a javascript file with the name of the controller will added automatically. Firstly, I thought this javascript file will used only, when the related controller is called.

By default there is the instruction //= require_tree . in the application.js-file, that include every javascript file on it's tree.

How could I load only the controller specific script?


Source: (StackOverflow)

How can I add JPEGs to an asset catalog in Xcode?

Is it possible to add assets other than PNG files to an Xcode Asset Catalog?

When I drag JPEG files into an Asset Catalog they aren't accepted by the UI.


Source: (StackOverflow)

The reason for Assets and Raw Resources in Android

this is some sort of a philosophical question .. . I'm in the mid of my studies in the Android world and I just covered the Assets and Raw resources.

I'm trying to understand the reason for using Raw resources vs. Assets.

  1. They both provide with an uncompiled resource input stream.

  2. It seems that Assets provide much more flexibility and functionality then Raw resources.

    a. You can create folder structure under Assets and not under Raw

    b. you can list all resources dynamically in the assets folder and not in the Raw folder.

So why would i use Raw resources in Android ?

Thanks.


Source: (StackOverflow)

Rails 3.1 and jquery-ui assets

This was asked in another question, but none of the solutions appear to work for me in 3.1rc1.

I'm trying to use the new assets stuff in rails 3.1 - I have the files:

./vendor/assets/stylesheets/jquery-ui-1.8.13.custom.css
./vendor/assets/javascripts/jquery-ui-1.8.13.custom.min.js

I then added:

//= require jquery-ui to app/assets/javascripts/application.js
*= require jquery-ui to app/assets/stylesheets/application.css

The jquery-ui javascript file loads just fine, but the css file says:

Sprockets::FileNotFound (couldn't find file 'jquery-ui'
     (in /home/xanview2/xancar/app/assets/stylesheets/application.css):6):

Any ideas?


Source: (StackOverflow)

Symfony2 - Assetic - load images in CSS

I have a CoreBundle that contains main css files and images. Now I have a problem when I load an image from css; the image isn't shown.

 background-image:url(../images/file.png)

(with a full path it works)

I installed the assets using the command: assets:install web and i can see the image and css files under web/bundles/cmtcore/(css|images).

Here's the file structure inside the core bundle:

/CoreBundle
    /Resources
        /public
            /css
                /main.css
            /images
                /file.png

And here's how I load the css file into the template:

 {% stylesheets '@CmtCoreBundle/Resources/public/css/*' %}
        <link rel="stylesheet" type="text/css" media="screen" rel='nofollow' href="{{ asset_url }}" />
 {% endstylesheets %}

Thank you for your help in advance.


Source: (StackOverflow)

How to play videos in android from assets folder or raw folder?

I am trying to play a video in android emulator I have the video in my assets folder as well as the raw folder But after doing some research still i cant play video in my emulator i am working on android 2.1 My video format is mp4 so i don't think that should be a problem Could anyone just give me an example code so that i can understand a bit more?

The problem is that the VideoView that I need to display the Video will take only a URI or a File path to point to the Video.

If I save the video in the raw or assets folder I can only get an input stream or a file descriptor and it seems nothing of that can be used to initialize the VideoView.

Update

I took a closer look at the MediaPlayer example and tried to start a MediaPlayer with a FileDescriptor to the assets files as in the code below:

SurfaceView videoView = (SurfaceView) findViewById(gettingStarted)
SurfaceHolder holder = videoView.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
final MediaPlayer player = new MediaPlayer();
player.setDisplay(holder);

player.setDataSource(getAssets().openFd(fileName).getFileDescriptor());
player.prepareAsync();
player.setOnPreparedListener(new OnPreparedListener() {

   @Override
   public void onPrepared(MediaPlayer mp) {
      mp.start();
   }
});

Now I get a the following exception:

java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

It seems there is no other way then copying the file to the sdcard on startup and that seems like a waste of time and memory.


Source: (StackOverflow)

Access Asset Catalog programmatically

I know it's a new feature and this may not be possible, but I would love to be able to use an Asset Catalog to organize my assets, but I access all of my images programmatically. How would I access my images, now? Do I still access them by their file names like so:

[UIImage imageNamed:@"my-asset-name.png"];

Seemingly, the Asset Catalog doesn't reference the extension, so would it be more efficient to access it without the ".png"?

The reason I am asking instead of testing for myself is that even after removing my assets and Asset Catalog, then cleaning the build folder, I can still access my assets in my application. This is preventing me from testing the Asset Catalog, when I implement it.

After looking through the Asset Catalog, I found the "Contents.json" for each asset and it's formatted like so:

{
  "images" : [
    {
      "idiom" : "universal",
      "scale" : "1x"
    },
    {
      "idiom" : "universal",
      "scale" : "2x",
      "filename" : "my-asset@2x.png"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

I'm still unsure of how I should be accessing it, but maybe this will help?


Source: (StackOverflow)

Should I use @import or manifest files?

Rails 3.1 introduces a new way of organizing both JS and CSS with the introduction of manifest files. For example, application.js might look like this:

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .

This will grab various bits of Jquery, all of your own JS, concatenate them together and serve it as a single file to clients. Simple enough.

Unfortunately the picture is not so clear to me with SASS. SASS already has concatenation built in using @import.

Should I change all of my partials into full SASS files and then concatenate them using the manifest file or continue using @import? Why?


Source: (StackOverflow)

How to avoid two files in project view when creating a custom importer in Unity3D?

NOTE: I'm casting a wider net than Unity Answers, my original question can be found here.

I've created a ProTools CueSheet importer. It uses OnPostprocessAllAssets() to detect a files in the project that have a .cuesheet extension. It then runs those cuesheet files through my parser. This generates a ScriptableObject which is then turned into an asset via Database.CreateAsset().

The problem is, this leaves me with two files, the original cuesheet and the newly generated asset. Is there any way I can generate the asset in such as way that the original cuesheet acts as the asset, the same way textures or FBX files do?

public class CueSheetPostProcessor : AssetPostprocessor {
    static string extension = ".cuesheet";

    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) {
        foreach (string assetPath in importedAssets) {
            if (assetPath.EndsWith(extension, StringComparison.OrdinalIgnoreCase)) {
                string newPath = assetPath + ".asset";
                Session session = CueImporter.Load(assetPath);
                AssetDatabase.CreateAsset(session, newPath);
                AssetDatabase.SaveAssets();
            }
        }
    }
}

Source: (StackOverflow)

Is it possible to load a drawable from the assets folder?

Can you load a drawable from a sub directory in the assets (not the drawable folder) folder?


Source: (StackOverflow)

Get NGINX to serve .gz compressed asset files

Rails 3.1 has a convenient system which can compress files into .gz files. However, instead what I've done is I've moved all the asset files that are created with assets:precompile to a static webserver. This all works, but how can I get nginx to serve the .gz files normally?


Source: (StackOverflow)