{"id":16209543,"url":"https://github.com/faizandurrani/unitybackgroundaudio","last_synced_at":"2025-10-14T10:09:51.949Z","repository":{"id":112120666,"uuid":"179532689","full_name":"FaizanDurrani/UnityBackgroundAudio","owner":"FaizanDurrani","description":" Play audio on mobile even when the game is suspended in the background","archived":false,"fork":false,"pushed_at":"2020-09-29T07:36:45.000Z","size":1733,"stargazers_count":35,"open_issues_count":3,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T00:51:47.153Z","etag":null,"topics":["android","audio","csharp","ios","native","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FaizanDurrani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-04T16:09:09.000Z","updated_at":"2025-03-03T06:07:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9450b11-8574-46ae-b562-2ae75ba6c0d5","html_url":"https://github.com/FaizanDurrani/UnityBackgroundAudio","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/FaizanDurrani/UnityBackgroundAudio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaizanDurrani%2FUnityBackgroundAudio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaizanDurrani%2FUnityBackgroundAudio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaizanDurrani%2FUnityBackgroundAudio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaizanDurrani%2FUnityBackgroundAudio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FaizanDurrani","download_url":"https://codeload.github.com/FaizanDurrani/UnityBackgroundAudio/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaizanDurrani%2FUnityBackgroundAudio/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018769,"owners_count":26086449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","audio","csharp","ios","native","unity"],"created_at":"2024-10-10T10:30:11.698Z","updated_at":"2025-10-14T10:09:51.929Z","avatar_url":"https://github.com/FaizanDurrani.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UnityBackgroundAudio\nPlay audio on mobile even when the game is suspended in the background\n\n## Dependencies\nThe following plug-ins are needed for UnityBackgroundAudio to work.\n- Unity-Swift - [Github](https://github.com/miyabi/unity-swift/releases)\n- Unity-Jar-Resolver [Github](https://github.com/googlesamples/unity-jar-resolver/releases)\n\n## Usage\nDownload and import the dependencies and the `.unitypackage` from [Releases](https://github.com/FaizanDurrani/UnityBackgroundAudio/releases)\n```cs\n// Get an instance of the BackgroundAudioImplementation class for the current build platform\nvar instance = BackgroundAudioManager.NewInstance();\n\n...\n\n// To play an mp3 file\n// NOTE: Network playback currently not supported\ninstance.Play(\"/Path/To/File.mp3\");\n\n...\n\n// Callbacks\n// NOTE: Callbacks on Android are not invoked on the main thread (use a main thread dispatcher to update UI)\ninstance.OnAudioStarted += () =\u003e Debug.Log(\"Audio started playing\");\ninstance.OnAudioStopped += () =\u003e Debug.Log(\"Audio stopped playing\");\ninstance.OnAudioPaused += () =\u003e Debug.Log(\"Audio paused\");\ninstance.OnAudioResumed += () =\u003e Debug.Log(\"Audio resumed\");\n```\n\n## Caveats (Android)\n#### Notification\nThe plugin starts a ForegroundService whenever an audio is played. This is required so that even if Android decides to kill the game the audio continues to play. To change the icon, simply replace the `ba_notification_icon.png` inside `Assets/Plugins/Android/res/drawable/` with your own icon.\n#### Threading\n`AndroidJNI.AttachCurrentThread();` must be called before calling any methods from outside the main thread and `AndroidJNI.DetachCurrentThread();` must be called before the thread closes.\n\n## Sample\nClone or download the repo as `.zip` and open the `SampleScene` scene under `Assets/Scenes/`\n\n## Notes\nI am still learning Native Plugin development for Android and iOS so there might be inefficient/bad code in the `.java` or `.swift` files. Feel free to criticize or submit pull requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaizandurrani%2Funitybackgroundaudio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaizandurrani%2Funitybackgroundaudio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaizandurrani%2Funitybackgroundaudio/lists"}