npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cordova-codeplay-music-controls

v0.0.8

Published

Android 12+ compatible music controls plugin for Cordova and Capacitor

Downloads

35

Readme

Cordova CodePlay Music Controls

A maintained and fixed Cordova music controls plugin for Android, iOS, and Windows.

This plugin shows a native media notification / lockscreen controller with play, pause, next, previous buttons and supports real seek and progress updates on Android, which were missing in the original plugin.


📌 About This Plugin

This repository is a cleaned, fixed, and maintained fork of the original, now unmaintained plugin:

Original Repository:
https://github.com/homerours/cordova-music-controls-plugin
Original Author: homerours

The original plugin contained multiple Android issues such as:

  • Seek mentioned in docs but not implemented
  • Progress bar displayed but never updated
  • Android 12+ BroadcastReceiver crashes
  • Broken MediaSession callback lifecycle
  • Duration metadata ignored on Android

All of these issues are fixed in this fork.


🔧 Maintainer

Maintained & Fixed by: Merbin Joe
GitHub: https://github.com/merbin2012
Repository: https://github.com/merbin2012/cordova-codeplay-music-controls


✅ Supported Platforms

  • Android 5.0+ (MediaSession based, Android 13/14 compatible)
  • iOS 8+
  • Windows 10+

📦 Installation

From GitHub (recommended maintained version)

cordova plugin add https://github.com/merbin2012/cordova-codeplay-music-controls

From npm (recommended for Capacitor & Ionic)

npm i cordova-codeplay-music-controls

📖 Usage

Create Media Controls

MusicControls.create({
  track       : 'My Audio Track',
  artist      : 'CodePlay',
  album       : '',
  cover       : 'https://example.com/cover.jpg',

  isPlaying   : true,
  dismissable : true,

  hasPrev     : true,
  hasNext     : true,
  hasClose    : true,

  // ✅ REQUIRED for progress bar & seek (Android)
  duration    : 380,   // seconds
  elapsed     : 10,    // seconds

  ticker      : 'Now playing My Audio Track',

  playIcon          : 'media_play',
  pauseIcon         : 'media_pause',
  prevIcon          : 'media_prev',
  nextIcon          : 'media_next',
  closeIcon         : 'media_close',
  notificationIcon  : 'notification'
}, onSuccess, onError);

⚠️ Android Note
The progress bar and seek scrubber work only when duration > 0 is provided.


🎧 Media Events

function events(action) {

  // `action` is already an object
  const message = action.message;

  switch (message) {

    case 'music-controls-play':
      audio.play();
      MusicControls.updateIsPlaying(true);
      break;

    case 'music-controls-pause':
      audio.pause();
      MusicControls.updateIsPlaying(false);
      break;

    case 'music-controls-next':
      playNext();
      break;

    case 'music-controls-previous':
      playPrevious();
      break;

    case 'music-controls-destroy':
      stopAudio();
      break;

    // ✅ REAL SEEK SUPPORT (Android + iOS)
    case 'music-controls-seek-to':
      // position is in milliseconds
      audio.currentTime = action.position / 1000;

      // notify native layer about new position
      MusicControls.updateElapsed({
        elapsed   : audio.currentTime * 1000,
        isPlaying : !audio.paused
      });
      break;
  }
}

MusicControls.subscribe(events);
MusicControls.listen();

⏱️ Progress Updates (REQUIRED FOR ANDROID)

Android does not automatically update media progress.
You must push progress updates from JavaScript.

setInterval(() => {
  if (!audio || isNaN(audio.currentTime)) return;

  MusicControls.updateElapsed({
    elapsed   : audio.currentTime * 1000, // milliseconds
    isPlaying : !audio.paused
  });
}, 1000);

✅ Keeps notification progress, lockscreen scrubber, and Bluetooth seek in sync.


🔄 Toggle Play / Pause

MusicControls.updateIsPlaying(true);
MusicControls.updateDismissable(true);

📱 Supported Media Button Events

music-controls-play
music-controls-pause
music-controls-next
music-controls-previous
music-controls-toggle-play-pause
music-controls-seek-to
music-controls-stop

Also supports headset and Bluetooth media buttons.


⚠️ Important Notes

Android Seek & Progress

  • Android never controls audio playback directly
  • JavaScript must apply seek and report progress
  • This plugin correctly bridges MediaSession → JS

Audio Events Best Practice

Avoid controlling playback in canplay.

Use:

  • loadedmetadata → initialization
  • timeupdate → progress
  • seeking / seeked → buffering UI

✅ Fixes Included in This Fork

  • ✅ Android seek implementation
  • ✅ Moving progress bar
  • ✅ Correct duration handling
  • ✅ MediaSession callback fixes
  • ✅ BroadcastReceiver crash fixes
  • ✅ Cordova callback lifecycle fixes
  • ✅ Android 13/14 compatibility
  • ✅ Capacitor support

Fully compatible with Capacitor + Ionic projects (tested with Capacitor & Ionic apps)


🧾 Credits

  • Original plugin by homerours
    https://github.com/homerours/cordova-music-controls-plugin

  • Maintained & fixed by Merbin Joe
    https://github.com/merbin2012


📄 License

Same license as the original project.