Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 20, 2025

This PR addresses runtime crashes (FlutterError PlatformException(DarwinAudioError, Failed to set source. AVPlayerItem.Status.failed)) when attempting to play audio URLs on iOS/macOS using the audioplayers library.

Problem

The current implementation allows users to add audio URLs that cause AVPlayer to fail on Darwin platforms due to:

  • Missing file extensions (required by AVPlayer)
  • Unsupported formats like .ogg on iOS
  • HTTP URLs that may be blocked by App Transport Security

These issues result in cryptic runtime errors that provide no guidance to users.

Solution

This PR implements comprehensive URL validation before audio sources are added, with user-friendly error messages and documentation links:

Validation Features

  1. File Extension Validation: Ensures URLs have proper file extensions on iOS/macOS

    // ❌ Before: "http://example.com/audio" → Runtime crash
    // ✅ After: Shows clear error with documentation link
  2. Format Compatibility: Warns about unsupported formats on iOS

    // ❌ Before: "https://example.com/audio.ogg" → Silent failure on iOS
    // ✅ After: "iOS does not support .ogg format. Please use .mp3 or .wav."
  3. Security Protocol Validation: Warns about HTTP URLs on iOS/macOS

    // ⚠️ "http://example.com/audio.mp3" → Warning but allows continuation
    // ✅ "https://example.com/audio.mp3" → No warning

Implementation Details

  • Added helper functions hasFileExtension(), isOgg(), and isHttpOnIOS() for clean validation logic
  • Enhanced the add() method with platform-specific checks that run before attempting audio playback
  • All error messages include links to relevant audioplayers troubleshooting documentation
  • HTTP warnings allow users to continue (non-blocking) while format/extension issues prevent submission

Testing

Added comprehensive unit tests covering all validation scenarios and edge cases.

Impact

This change should significantly reduce audio playback crashes on iOS/macOS while providing users with actionable feedback to resolve URL issues. The implementation is minimal and preserves all existing functionality for valid URLs.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Improve audio source validation to prevent AVPlayer failures on iOS/macOS Fix iOS/macOS audio playback crashes with enhanced URL validation Aug 20, 2025
Copilot AI requested a review from kevmo314 August 20, 2025 04:16
Copilot finished work on behalf of kevmo314 August 20, 2025 04:16
@kevmo314 kevmo314 closed this Aug 20, 2025
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.

2 participants