Jump to content
  • Advertisement
Sign in to follow this  
3DModelerMan

Playing music from the assets folder

This topic is 2158 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to stream music that's stored in my assets folder, but it never works. I've already verified that filepath contains the correct local path from the root of my assets folder. I need to use AsyncPlayer so that I can stream music instead of loading it into memory. I use ogg files. I attached the debug output from logcat as well. How do you get a URI to a file in the assets folder that can be used with AsyncPlayer?

[attachment=12510:Screenshot from 2012-11-28 13:04:21.png]


public class MusicWrapper
{
public static void setContext(Context context)
{
m_context = context;

m_player = new AsyncPlayer(null);
}

public static void playTrack(String filepath)
{
m_player.play(m_context, Uri.parse("file:///android_asset/"+filepath), true, AudioManager.STREAM_MUSIC);
}

private static AsyncPlayer m_player;

private static Context m_context;
}

Share this post


Link to post
Share on other sites
Advertisement
[s]You're missing an s on your path, I believe. Try "file:///android_assets/"[/s]. Nevermind. The Internets seem to be conflicting on this, with some sites saying "file:///android_asset/" and some saying "file:///android_assets/". So far, I've only seen WebView use that path, so it's possible the AsyncPlayer doesn't work with that path. [Edit again: I asked about this path on StackOverflow (there are more Android devs there), for the curious]

If that doesn't work, seriously consider using the MediaPlayer. AFAIK, it doesn't load the entire audio clip into memory, and can stream. Edited by Cornstalks

Share this post


Link to post
Share on other sites

I didn't know about ClassLoader.getResource. Thanks for the help. 'll just try both the extra s and without it and see what works.

I think that the android_asset and android_res directories only work with WebView. I don't think you can use it with other objects (or at least I'm failing to find any example of it being possible). AsyncPlayer was intended for playing audio files from an external server. I still think you really aught to be using MediaPlayer (are you already using MediaPlayer? because I can't tell if those MediaPlayer log entries in your log you posted are from you or from AsyncPlayer (which may just be a wrapper for MediaPlayer)).

Share this post


Link to post
Share on other sites

why use assets in first place? use raw and your media files will get indexed and then its strigtforward playback usin soundpool and mediaplayer

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!