{"id":30753857,"url":"https://github.com/mahdirahmatii/unity-webgl-webaudio","last_synced_at":"2026-04-13T01:34:19.154Z","repository":{"id":309563941,"uuid":"1036747696","full_name":"MahdiRahmatii/Unity-WebGL-WebAudio","owner":"MahdiRahmatii","description":"🎵 Unity WebGL Audio Context Manager - Automatic audio lifecycle management for WebGL builds. Handles mobile browsers, tab switching, and AudioContext recovery seamlessly.","archived":false,"fork":false,"pushed_at":"2025-08-12T14:41:13.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-12T16:30:23.931Z","etag":null,"topics":["android-chrome","audio-context","audio-management","csharp","game-development","ios-safari","javascript","mobile-web","unity","unity-package","unity-plugin","unity3d","web-audio","web-browser","webgl"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/MahdiRahmatii.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,"zenodo":null}},"created_at":"2025-08-12T14:23:03.000Z","updated_at":"2025-08-12T14:50:28.000Z","dependencies_parsed_at":"2025-08-12T16:30:25.078Z","dependency_job_id":"6850e60d-0dd4-4870-a994-ff0288b9eee3","html_url":"https://github.com/MahdiRahmatii/Unity-WebGL-WebAudio","commit_stats":null,"previous_names":["mahdirahmatii/unity-webgl-webaudio"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/MahdiRahmatii/Unity-WebGL-WebAudio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiRahmatii%2FUnity-WebGL-WebAudio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiRahmatii%2FUnity-WebGL-WebAudio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiRahmatii%2FUnity-WebGL-WebAudio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiRahmatii%2FUnity-WebGL-WebAudio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MahdiRahmatii","download_url":"https://codeload.github.com/MahdiRahmatii/Unity-WebGL-WebAudio/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MahdiRahmatii%2FUnity-WebGL-WebAudio/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273581133,"owners_count":25131392,"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-09-04T02:00:08.968Z","response_time":61,"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-chrome","audio-context","audio-management","csharp","game-development","ios-safari","javascript","mobile-web","unity","unity-package","unity-plugin","unity3d","web-audio","web-browser","webgl"],"created_at":"2025-09-04T09:02:15.799Z","updated_at":"2026-04-13T01:34:19.119Z","avatar_url":"https://github.com/MahdiRahmatii.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity-WebGL-WebAudio\n\nA robust Unity plugin that automatically manages Web Audio API contexts in WebGL builds, ensuring reliable audio playback across different browsers and device states.\n\n## 🎯 Overview\n\nThis plugin solves common WebGL audio issues by intelligently handling AudioContext lifecycle events, including:\n- Browser tab visibility changes\n- Mobile device sleep/wake cycles  \n- User interaction requirements for audio initialization\n- AudioContext suspension and resumption\n- Automatic recovery from closed/invalid audio contexts\n\n## ✨ Features\n\n- **Automatic AudioContext Management**: Handles suspend/resume cycles seamlessly\n- **Mobile-Optimized**: Designed for iOS Safari and Android Chrome compatibility\n- **Zero Configuration**: Works out of the box with Unity's audio system\n- **Lightweight**: Minimal performance impact with smart event handling\n- **Error Recovery**: Automatically recreates AudioContext when needed\n- **Debug Logging**: Comprehensive console output for troubleshooting\n\n## 🚀 Quick Start\n\n### Installation\n\n1. Download the latest release or clone this repository\n2. Copy both files to your Unity project's `Plugins/WebGL` folder:\n   ```\n   Assets/\n   └── Plugins/\n       └── BrowserWEBAudio/\n           ├── BrowserWEBAudio.cs\n           └── BrowserWEBAudio.jslib\n   ```\n3. Add the `BrowserWEBAudio` component to any GameObject in your first scene\n4. Build for WebGL - the plugin activates automatically!\n\n### Folder Structure\n```\nYourUnityProject/\n├── Assets/\n│   └── Plugins/\n│       └── BrowserWEBAudio/\n│           ├── BrowserWEBAudio.cs      # Unity C# component\n│           └── BrowserWEBAudio.jslib   # JavaScript library\n└── ...\n```\n\n## 🔧 How It Works\n\n### The Problem\nWebGL audio faces several challenges:\n- Browsers require user interaction before playing audio\n- Mobile browsers suspend AudioContext when tabs become inactive\n- AudioContext can become permanently closed on some devices\n- Unity's built-in WebGL audio doesn't always handle edge cases\n\n### The Solution\nThis plugin provides:\n\n1. **Visibility Management**: Automatically suspends audio when the tab is hidden and resumes when visible\n2. **Touch Activation**: Ensures AudioContext is ready after user interaction\n3. **Smart Recovery**: Detects closed AudioContext and recreates it when needed\n4. **Delayed Resume**: Accounts for mobile device audio hardware initialization delays\n\n## 📱 Browser Compatibility\n\n| Browser | Desktop | Mobile |\n|---------|---------|--------|\n| Chrome | ✅ | ✅ |\n| Firefox | ✅ | ✅ |\n| Safari | ✅ | ✅ |\n| Edge | ✅ | ✅ |\n\n## 🛠️ Technical Details\n\n### Component Lifecycle\n```csharp\nvoid Start()\n{\n#if UNITY_WEBGL \u0026\u0026 !UNITY_EDITOR\n    InitBrowserWEBAudio(); // Only runs in WebGL builds\n#endif\n}\n```\n\n### JavaScript Events Handled\n- `visibilitychange`: Tab focus/blur management\n- `touchstart`: Mobile interaction detection\n- AudioContext state monitoring\n\n### Performance Characteristics\n- **Memory Usage**: \u003c 1KB runtime footprint\n- **CPU Impact**: Event-driven, no polling\n- **Audio Latency**: No additional latency introduced\n\n## 📄 API Reference\n\n### C# Component\n```csharp\npublic class BrowserWEBAudio : MonoBehaviour\n{\n    // Automatically initializes on Start() in WebGL builds only\n    // No public methods - fully automatic operation\n}\n```\n\n### JavaScript Functions\n```javascript\n// Internal functions (not for direct use)\nInitBrowserWEBAudio()    // Main initialization\nrecreateAudioContext()   // Emergency recovery function\n```\n\n## 📝 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🙏 Acknowledgments\n\n- Unity Technologies for WebGL audio architecture\n- Web Audio API specification contributors\n- Community feedback and testing\n\n---\n\n**Made with ❤️ for Unity developers struggling with WebGL audio**\n\n*If this plugin helped your project, consider giving it a ⭐ on GitHub!*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahdirahmatii%2Funity-webgl-webaudio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmahdirahmatii%2Funity-webgl-webaudio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahdirahmatii%2Funity-webgl-webaudio/lists"}