Welcome to JcPlayer: A Simple Audio Player for Android

Jun 9, 2024 | Programming

Unleashing the power of audio playback in your Android applications has never been simpler. JcPlayer is a delightful audio player that enables you to integrate seamless audio experiences into your apps effortlessly.

New Features

  • Supports raw audio files
  • Handles asset audio files
  • Custom layout options for a personalized touch

Getting Started with JcPlayer

To start making your app sing, you only need to include a JcPlayerView in your Activity or Fragment layout. The beauty of this player lies in its ability to take care of most UI duties on its own!



Code Setup: Getting Your Audio Player Ready

Now that you have your JcPlayerView embedded, it’s time to initialize it in your activity. Here’s how you can do that:


// Find your JcPlayerView in the layout
jcplayerView = (JcPlayerView) findViewById(R.id.jcplayer);

Option 1: Setting Up a Playlist

An analogy to understand this process is to think of your JcPlayer as a restaurant where you can serve different dishes:

  • **Appetizers**: Starting with audio from a URL.
  • **Mains**: Adding audio from your asset files.
  • **Dessert**: Serving up audio from your raw resources.

Here’s how you set this up:


ArrayList jcAudios = new ArrayList<>();
jcAudios.add(JcAudio.createFromURL("audio", "http://xxxx/audio.mp3"));
jcAudios.add(JcAudio.createFromAssets("audio", "audio.mp3"));
jcAudios.add(JcAudio.createFromRaw("audio", R.raw.audio));
jcplayerView.initPlaylist(jcAudios, null);

Option 2: Anonymous Playlist Initialization


jcplayerView.initAnonPlaylist(jcAudios);

Option 3: Custom Title Playlist


jcplayerView.initWithTitlePlaylist(urls, "Awesome music");

Notification Player

When music is playing, wouldn’t you want to have a notification popping up? Call the notification player whenever you’re in the mood:


jcplayerView.createNotification(); // default icon
jcplayerView.createNotification(R.drawable.myIcon); // custom icon

Callbacks for Player Status

To keep track of your player’s status, make your activity implement the JcPlayerManagerListener:


class MyActivity implements JcPlayerManagerListener {
    // your code
}
jcplayerView.setJcPlayerManagerListener(this);

Custom Layout Options

JcPlayer allows you to customize the layout by manipulating various attributes to create a unique player visual:


app:next_icon
app:pause_icon
app:play_icon
app:previous_icon
app:progress_color
...and many more!

Troubleshooting Ideas

  • If you followed the steps but your player isn’t working, ensure that the URLs you are using are correct and accessible.
  • Not seeing audio playback? Make sure your audio files are properly included as asset or raw resources.
  • Check to see if your music files are supported by JcPlayer. Some formats may not work.
  • For any persistent issues, for insights or collaboration, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox