Code Monkey home page Code Monkey logo

Comments (2)

sonigeez avatar sonigeez commented on May 23, 2024

how does i confirm it is i cloned SoLoud and removed the condition

original

 static Future<SoundProps?> loadFromUrl(String url) async {
    try {
      final now = DateTime.now();
      final tempDir = await getTemporaryDirectory();
      final tempPath = tempDir.path;
      final filePath = '$tempPath${Platform.pathSeparator}'
          '${now.year} ${now.month} ${now.day}';
      final file = File(filePath);

      if (!file.existsSync()) {
        final response = await http.get(Uri.parse(url));
        if (response.statusCode == 200) {
          final byteData = response.bodyBytes;
          final buffer = byteData.buffer;
          await file.create(recursive: true);
          await file.writeAsBytes(
            buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes),
          );
        } else {
          debugPrint('Failed to fetch file from URL: $url');
          return null;
        }
      }
      return _finallyLoadFile(file);
    } catch (e) {
      debugPrint('Error while fetching file: $e');
      return null;
    }
  }

my workaround

 static Future<SoundProps?> loadFromUrl(String url) async {
  try {
    final now = DateTime.now();
    final tempDir = await getTemporaryDirectory();
    final tempPath = tempDir.path;
    final filePath = '$tempPath${Platform.pathSeparator}'
        '${now.year} ${now.month} ${now.day}';
    final file = File(filePath);

    // ignore: literal_only_boolean_expressions
    if (true) {
      final response = await http.get(Uri.parse(url));
      if (response.statusCode == 200) {
        final byteData = response.bodyBytes;
        final buffer = byteData.buffer;
        await file.create(recursive: true);
        await file.writeAsBytes(
          buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes),
        );
      } else {
        debugPrint('Failed to fetch file from URL: $url');
        return null;
      }
    }
    return _finallyLoadFile(file);
  } catch (e) {
    debugPrint('Error while fetching file: $e');
    return null;
  }
}

from flutter_soloud.

alnitak avatar alnitak commented on May 23, 2024

Thanks for reporting this!

Sorry for the late but my PC motherboard burned!!! (not this lib fault :) )
I would change the generated temp file name using the String url hash code like replacing this

final filePath = '$tempPath${Platform.pathSeparator}'
        '${now.year} ${now.month} ${now.day}';

with this

final filePath = '$tempPath${Platform.pathSeparator}'
          '${shortHash(url)}';

doing so the url string becomes almost unique and the sound remains cached.
Let me know if this is working for you

from flutter_soloud.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.