Skip to content

Integrate native audio focus and webview reload support#151

Merged
marc-n-dream merged 11 commits intomasterfrom
marc-android-native
Dec 11, 2025
Merged

Integrate native audio focus and webview reload support#151
marc-n-dream merged 11 commits intomasterfrom
marc-android-native

Conversation

@marc-n-dream
Copy link
Collaborator

No description provided.

@marc-n-dream marc-n-dream requested a review from Copilot December 11, 2025 10:03
@marc-n-dream
Copy link
Collaborator Author

@codex review

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR integrates native audio focus management and webview reload support to improve Android platform behavior, particularly for Android Automotive. Key changes include implementing thread-safe event handling for WebView callbacks, adding audio focus state management with volume control, and replacing webview recreation with reload-based navigation.

Key Changes:

  • Introduced thread-safe event queue architecture for WebView callbacks to handle cross-thread communication from native Android code
  • Added native audio focus management with maximum volume tracking to comply with Android Automotive requirements
  • Replaced full webview recreation with reload-based navigation to improve performance and reliability

Reviewed changes

Copilot reviewed 35 out of 50 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
CHANGELOG.md Updated with Android support improvements and audio focus enhancements
Assets/WebGLTemplates/AirConsole-U6/airconsole-unity-plugin.js Added Android TV detection workaround for native game sizing
Assets/AirConsole/unity-webview/Runtime/WebViewObject.cs Implemented thread-safe event queue and removed polling-based message retrieval
Assets/AirConsole/unity-webview/Runtime/WebViewEvent.cs New event model for thread-safe WebView communication
Assets/AirConsole/unity-webview/Runtime/WebViewCallback.cs New direct callback bridge from Java to C#
Assets/AirConsole/scripts/Runtime/AirConsole.cs Added audio focus management and OnGameAudioFocusChanged event
Assets/AirConsole/scripts/Runtime/Plugin/Android/PluginManager.cs Added volume and audio focus change event handlers
Assets/AirConsole/scripts/Editor/BuildAutomation/AndroidGradleProcessor.cs Refactored dependency injection logic
Assets/AirConsole/examples/basic/AudioManager.cs New example showing proper audio focus handling
Assets/Packager/Editor/Packager.cs Removed webview package extraction logic
AGENTS.md Added comprehensive project documentation for AI agents
Files not reviewed (2)
  • .idea/.idea.airconsole-unity-plugin/.idea/codeStyles/Project.xml: Language not supported
  • .idea/.idea.airconsole-unity-plugin/.idea/codeStyles/codeStyleConfig.xml: Language not supported
Comments suppressed due to low confidence (1)

Assets/AirConsole/scripts/Editor/BuildAutomation/AndroidGradleProcessor.cs:95

  • Using target-typed new expression 'new()' requires C# 9.0 or later. Verify that the project's C# language version is configured to support this syntax to avoid compilation errors in older Unity versions.
            List<string> lines = new();

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2547 to +2551
case "NATIVE_AUDIOFOCUS_LOSS":
AirConsoleLogger.Log(() =>
$"{command}: Can ignore native loss={_canIgnoreNativeAudioLoss}");

if (_canIgnoreNativeAudioLoss) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update HasAudioFocus when native focus is lost

In the native audio focus loss branch the code logs and conditionally returns but never sets HasAudioFocus to false, even though the gain branches above set it to true. When Android delivers NATIVE_AUDIOFOCUS_LOSS (e.g., another app grabs audio), the API property remains true despite focus having been revoked, so game code that relies on HasAudioFocus will keep playing sound after a loss unless it separately tracks the event argument.

Useful? React with 👍 / 👎.

@marc-n-dream marc-n-dream marked this pull request as ready for review December 11, 2025 10:35
@marc-n-dream marc-n-dream merged commit 43904e4 into master Dec 11, 2025
1 check passed
@marc-n-dream marc-n-dream deleted the marc-android-native branch December 11, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant