Giter Club home page Giter Club logo

cache_audio_player's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cache_audio_player's Issues

lengthInseconds() returns invalid length when media item has not loaded yet.

Hi, great plugin! Thanks a lot for the effort.

From what I can tell, if the item at the url has not finished loading by the time lengthInSeconds() is called, totalDuration is invalid, and no error is provided. Since loadUrl does not return a future, there is no robust way that I know of to wait until it is entirely loaded. I thought that since lengthInseconds() returns a future, it might return the value after the url has been loaded, but I don't think this is happening. If I sleep for a second after loadUrl is called, lengthInseconds appears to function as expected. Currently, I'm set up a delayed Future and just hope that after a few seconds the file has been loaded.

In the example code, this problem is avoided since the url is loaded at init time, but this is not appropriate for my application.

cant run in ios

Xcode's output:
โ†ณ
ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
ld: warning: Could not find or use auto-linked library 'swiftCore'
ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find or use auto-linked library 'swiftDarwin'
ld: warning: Could not find or use auto-linked library 'swiftUIKit'
ld: warning: Could not find or use auto-linked library 'swiftFoundation'
ld: warning: Could not find or use auto-linked library 'swiftsimd'
ld: warning: Could not find or use auto-linked library 'swiftCompatibility51'
ld: warning: Could not find or use auto-linked library 'swiftMetal'
ld: warning: Could not find or use auto-linked library 'swiftCompatibility50'
ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
ld: warning: Could not find or use auto-linked library 'swiftCompatibilityDynamicReplacements'
ld: warning: Could not find or use auto-linked library 'swiftDispatch'
ld: warning: Could not find or use auto-linked library 'swiftCoreMedia'
ld: warning: Could not find or use auto-linked library 'swiftAVFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCoreAudio'
ld: warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
ld: warning: Could not find or use auto-linked library 'swiftCoreMIDI'
ld: warning: Could not find or use auto-linked library 'swiftUniformTypeIdentifiers'
Undefined symbols for architecture arm64:
"protocol witness table for Swift.Int : Swift.CustomStringConvertible in Swift", referenced from:
cache_audio_player.MediaDownloadStreamHandler.errorReceived(error: __C.NSError) -> () in libcache_audio_player.a(MediaDownloadStreamHandler.o)
"Swift.DefaultStringInterpolation.appendInterpolation(A) -> ()", referenced from:
cache_audio_player.MediaDownloadStreamHandler.errorReceived(error: __C.NSError) -> () in libcache_audio_player.a(MediaDownloadStreamHandler.o)
"Swift.Dictionary.init(dictionaryLiteral: (A, B)...) -> [A : B]", referenced from:
cache_audio_player.MediaDownloadStreamHandler.bufferWasUpdated(newValue: Swift.Double) -> () in libcache_audio_player.a(MediaDownloadStreamHandler.o)
cache_audio_player.MediaDownloadStreamHandler.stateWasUpdated(newState: cache_audio_player.AudioPlayerState) -> () in libcache_audio_player.a(MediaDownloadStreamHandler.o)
cache_audio_player.MediaDownloadStreamHandler.timeElapsed(newTimeInSeconds: Swift.Double) -> () in libcache_audio_player.a(MediaDownloadStreamHandler.o)
"Swift.DefaultStringInterpolation.init(literalCapacity: Swift.Int, interpolationCount: Swift.Int) -> Swift.DefaultStringInterpolation", referenced from:
cache_audio_player.SwiftCacheAudioPlayerPlugin.handle(: __C.FlutterMethodCall, result: (Any?) -> ()) -> () in libcache_audio_player.a(SwiftCacheAudioPlayerPlugin.o)
cache_audio_player.MediaDownloadStreamHandler.errorReceived(error: __C.NSError) -> () in libcache_audio_player.a(MediaDownloadStreamHandler.o)
"protocol witness table for Swift.String : Swift.TextOutputStreamable in Swift", referenced from:
cache_audio_player.SwiftCacheAudioPlayerPlugin.handle(
: __C.FlutterMethodCall, result: (Any?) -> ()) -> () in libcache_audio_player.a(SwiftCacheAudioPlayerPlugin.o)
"Swift.DefaultStringInterpolation.appendInterpolation<A where A: Swift.CustomStringConvertible, A: Swift.TextOutputStreamable>(A) -> ()", referenced from:
cache_audio_player.SwiftCacheAudioPlayerPlugin.handle(_: __C.FlutterMethodCall, result: (Any?) -> ()) -> () in libcache_audio_player.a(SwiftCacheAudioPlayerPlugin.o)
"method descriptor for Swift.SetAlgebra.init<A where A1: Swift.Sequence, A.Element == A1.Element>(__owned A1) -> A", referenced from:
l_got.$ss10SetAlgebraPyxqd__ncSTRd__7ElementQyd__ACRtzlufCTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.isSuperset(of: A) -> Swift.Bool", referenced from:
l_got.$ss10SetAlgebraP10isSuperset2ofSbx_tFTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.isDisjoint(with: A) -> Swift.Bool", referenced from:
l_got.$ss10SetAlgebraP10isDisjoint4withSbx_tFTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.subtracting(A) -> A", referenced from:
l_got.$ss10SetAlgebraP11subtractingyxxFTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.formUnion(__owned A) -> ()", referenced from:
l_got.$ss10SetAlgebraP9formUnionyyxnFTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.update(with: __owned A.Element) -> A.Element?", referenced from:
l_got.$ss10SetAlgebraP6update4with7ElementQzSgAFn_tFTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.remove(A.Element) -> A.Element?", referenced from:
l_got.$ss10SetAlgebraP6removey7ElementQzSgAEFTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.symmetricDifference(__owned A) -> A", referenced from:
l_got.$ss10SetAlgebraP19symmetricDifferenceyxxnFTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.union(__owned A) -> A", referenced from:
l_got.$ss10SetAlgebraP5unionyxxnFTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.contains(A.Element) -> Swift.Bool", referenced from:
l_got.$ss10SetAlgebraP8containsySb7ElementQzFTq in libcache_audio_player.a(AudioPlayer.o)
"base conformance descriptor for Swift.SetAlgebra: Swift.ExpressibleByArrayLiteral", referenced from:
l_got.$ss10SetAlgebraPs25ExpressibleByArrayLiteralTb in libcache_audio_player.a(AudioPlayer.o)
"protocol descriptor for Swift.SetAlgebra", referenced from:
l_got.$ss10SetAlgebraMp in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for static Swift._ObjectiveCBridgeable.conditionallyBridgeFromObjectiveC(: A._ObjectiveCType, result: inout A?) -> Swift.Bool", referenced from:
l_got.$ss21_ObjectiveCBridgeableP024_conditionallyBridgeFromA1C_6resultSb01_A5CTypeQz_xSgztFZTq in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.SetAlgebra.isEmpty.getter : Swift.Bool", referenced from:
l_got.$ss10SetAlgebraP7isEmptySbvgTq in libcache_audio_player.a(AudioPlayer.o)
"associated type descriptor for Swift._ObjectiveCBridgeable._ObjectiveCType", referenced from:
l_got.$s15_ObjectiveCTypes01_A11CBridgeablePTl in libcache_audio_player.a(AudioPlayer.o)
"protocol descriptor for Swift._ObjectiveCBridgeable", referenced from:
l_got.$ss21_ObjectiveCBridgeableMp in libcache_audio_player.a(AudioPlayer.o)
"base conformance descriptor for Swift._SwiftNewtypeWrapper: Swift._HasCustomAnyHashableRepresentation", referenced from:
l_got.$ss20_SwiftNewtypeWrapperPs35_HasCustomAnyHashableRepresentationTb in libcache_audio_player.a(AudioPlayer.o)
"protocol descriptor for Swift._SwiftNewtypeWrapper", referenced from:
l_got.$ss20_SwiftNewtypeWrapperMp in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.OptionSet.init(rawValue: A.RawValue) -> A", referenced from:
l_got.$ss9OptionSetP8rawValuex03RawD0Qz_tcfCTq in libcache_audio_player.a(AudioPlayer.o)
"base conformance descriptor for Swift.OptionSet: Swift.SetAlgebra", referenced from:
l_got.$ss9OptionSetPs0B7AlgebraTb in libcache_audio_player.a(AudioPlayer.o)
"base conformance descriptor for Swift.OptionSet: Swift.RawRepresentable", referenced from:
l_got.$ss9OptionSetPSYTb in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.ExpressibleByArrayLiteral.init(arrayLiteral: A.ArrayLiteralElement...) -> A", referenced from:
l_got.$ss25ExpressibleByArrayLiteralP05arrayD0x0cD7ElementQzd_tcfCTq in libcache_audio_player.a(AudioPlayer.o)
"protocol descriptor for Swift.ExpressibleByArrayLiteral", referenced from:
l_got.$ss25ExpressibleByArrayLiteralMp in libcache_audio_player.a(AudioPlayer.o)
"protocol descriptor for Swift.RawRepresentable", referenced from:
l_got.$sSYMp in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.Hashable._rawHashValue(seed: Swift.Int) -> Swift.Int", referenced from:
l_got.$sSH13_rawHashValue4seedS2i_tFTq in libcache_audio_player.a(AudioPlayer.o)
"base conformance descriptor for Swift._SwiftNewtypeWrapper: Swift.RawRepresentable", referenced from:
l_got.$ss20_SwiftNewtypeWrapperPSYTb in libcache_audio_player.a(AudioPlayer.o)
"method descriptor for Swift.Hashable.hashValue.getter : Swift.Int", referenced from:
l_got.$sSH9hashValueSivgTq in libcache_audio_player.a(AudioPlayer.o)
"nominal type descriptor for Foundation.Data", referenced from:
_symbolic _____ 10Foundation4DataV in libcache_audio_player.a(AudioPlayer.o)
"protocol descriptor for Swift.Hashable", referenced from:
l_got.$sSHMp in libcache_audio_player.a(AudioPlayer.o)
"protocol descriptor for Swift.Equatable", referenced from:
l_got.$sSQMp in libcache_audio_player.a(AudioPlayer.o)
"Foundation.Data.init() -> Foundation.Data", referenced from:
variable initialization expression of cache_audio_player.AudioPlayer.(downloadedData in 43EF76CB7EE0DFBFF167F105B3D88BD3) : Foundation.Data in libcache_audio_player.a(AudioPlayer.o)
cache_audio_player.AudioPlayer.init() -> cache_audio_player.AudioPlayer in libcache_audio_player.a(AudioPlayer.o)
cache_audio_player.AudioPlayer.unregisterListeners() -> () in libcache_audio_player.a(AudioPlayer.o)
cache_audio_player.AudioPlayer.urlSession(
: __C.NSURLSession, dataTask: __C.NSURLSessionDataTask, didReceive: __C.NSURLResponse, completionHandler: (__C.NSURLSessionResponseDisposition) -> ()) -> () in libcache_audio_player.a(AudioPlayer.o)
"_swift_FORCE_LOAD$_swiftCompatibility50", referenced from:
_swift_FORCE_LOAD$swiftCompatibility50$_cache_audio_player in libcache_audio_player.a(AudioPlayer.o)
_swift_FORCE_LOAD$swiftCompatibility50$_cache_audio_player in libcache_audio_player.a(SwiftCacheAudioPlayerPlugin.o)
_swift_FORCE_LOAD$swiftCompatibility50$_cache_audio_player in libcache_audio_player.a(MediaDownloadStreamHandler.o)
(maybe you meant: _swift_FORCE_LOAD$swiftCompatibility50$_cache_audio_player)
"value witness table for Builtin.UnknownObject", referenced from:
full type metadata for __C.NSKeyValueChangeKey in libcache_audio_player.a(AudioPlayer.o)
full type metadata for cache_audio_player.(Cache in _43EF76CB7EE0DFBFF167F105B3D88BD3).Key in libcache_audio_player.a(AudioPlayer.o)
full type metadata for cache_audio_player.AudioPlayer in libcache_audio_player.a(AudioPlayer.o)
full type metadata for cache_audio_player.SwiftCacheAudioPlayerPlugin in libcache_audio_player.a(SwiftCacheAudioPlayerPlugin.o)
full type metadata for cache_audio_player.MediaDownloadStreamHandler in libcache_audio_player.a(MediaDownloadStreamHandler.o)
"_swift_FORCE_LOAD$_swiftCoreAudio", referenced from:
_swift_FORCE_LOAD$swiftCoreAudio$_cache_audio_player in libcache_audio_player.a(AudioPlayer.o)
_swift_FORCE_LOAD$swiftCoreAudio$_cache_audio_player in libcache_audio_player.a(SwiftCacheAudioPlayerPlugin.o)
_swift_FORCE_LOAD$swiftCoreAudio$_cache_audio_player in libcache_audio_player.a(MediaDownloadStreamHandler.o)
(maybe you meant: _swift_FORCE_LOAD$swiftCoreAudio$_cache_audio_player)

how to close cache log

register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554
D/BufferPoolManager(30744): register existing connection 3630857571634
D/BufferPoolManager(30744): register existing connection 132046085079554

Can't work with other caching package

There was an error PlatformException(,java.lang.IllegalStateException: Another SimpleCache instance uses the folder: /data/user/0/com.example.myapp/cache/media, null, null)

I used it with cached_video_player: ^1.0.3

Multiple Audio Players don't work on the same page

Hi Adriana, great plugin you have here

I created an issue earlier 'Can't work with other caching package' which I'm still trying to fix but i also noticed another issue which is strange. I cannot have 2 instance of the CacheAudioPlayer on the same application even with different variable name.

I had gone ahead in trying to fix the issue but couldn't find the issue

I created a constructor method in the CacheAudioPlayer class and changed the final and static properties of the class to dynamics and instantiated them in the constructor; then I called them with the new keyword as-in

aAudioPlayer = new CacheAudioPlayer();
bAudioPlayer = new CacheAudioPlayer();

But this couldn't help still.
Please can you fix it? Thanks

import 'dart:async';
import 'package:flutter/services.dart';

/// Enum representing the multiple states the Audio player can have.
enum AudioPlayerState {
  // [iOS] - State returned by AVPlayer, or set when buffering is finshed and audio is not being played.
  // [Android] - State returned by ExoPlayer
  // Value 0
  READYTOPLAY,
  // [iOS] - Set when the audio is being loaded successfully from URL, until loading completes.
  // [Android] - State returned by ExoPlayer.
  // Value 1
  BUFFERING,
  // [BOTH] - Set when player is playing audio file
  // Value 2
  PLAYING,
  // [BOTH] - Set when player is paused
  // Value 3
  PAUSED,
  // [BOTH] - Set if there is any error returned by player.
  // Value 4
  FAILED,
  // [BOTH] - Set when the player reaches the end of current media file.
  // Value 5
  FINISHED
}

///Main class of the plugin. Its functions are the following:
///Register listeners to the event channel where the player state, current time ellapsed, and buffer percentage, will be transmitted.
///Receive events from the client via the 'audio_player' MethodChannel and call the audio player methods accordingly.
class CacheAudioPlayer {
  // Constructor
  CacheAudioPlayer() {

    this._eventChannel = EventChannel('audio_player_streaming');

    this._channel = const MethodChannel('audio_player');

    this._errorController = StreamController<Object>.broadcast();

    this._bufferedMediaController = StreamController<double>.broadcast();

    this._timeElapsedController = StreamController<double>.broadcast();

    this._playerStateController =
        StreamController<AudioPlayerState>.broadcast();
  }

  ///Channel used to invoke AvPlayer methods on iOS and Exoplayer methods in Android
  ///Handles: play, stop, seek, load_from_url, length_in_seconds, unregister_listeners
  // static const MethodChannel _channel = const MethodChannel('audio_player');
  MethodChannel _channel;

  ///Channel used to stream the state updates from native players.
  ///Handles: state, buffer, time, errors
  // static const EventChannel _eventChannel =
  //     EventChannel('audio_player_streaming');
  EventChannel _eventChannel;

  ///Receives the percentage buffered in player.
  // final StreamController<double> _bufferedMediaController =
  //     StreamController<double>.broadcast();
  StreamController<double> _bufferedMediaController;

  ///Receives time elapsed (if player is playing) in seconds.
  // final StreamController<double> _timeElapsedController =
  //     StreamController<double>.broadcast();
  StreamController<double> _timeElapsedController;

  ///Receives any error returned from native, player errors or network request errors.
  // final StreamController<Object> _errorController =
  //     StreamController<Object>.broadcast();
  StreamController<Object> _errorController;

  ///Receives the player updated states: in AudioPlayerState.
  // final StreamController<AudioPlayerState> _playerStateController =
  //     StreamController<AudioPlayerState>.broadcast();
  StreamController<AudioPlayerState> _playerStateController;

  ///Stream that transmits the buffered percentage in a 'double' value that goes from 1 - 100.
  Stream<double> get onPlayerBuffered => _bufferedMediaController.stream;

  ///Stream that transmits the time ellapsed in a 'double' value that goes from 0 - audio duration.
  ///This stream will only transmit events if the audio player has a state of 'AudioPlayerState.PLAYING'
  Stream<double> get onTimeElapsed => _timeElapsedController.stream;

  ///Stream that transmits a change in the state of the audio player in a 'AudioPlayerState'.
  Stream<AudioPlayerState> get onStateChanged => _playerStateController.stream;

  ///Stream that transmits any error received while trying to load the audio into the player, or while playing the loaded audio.
  Stream<Object> get onError => _errorController.stream;

  ///Registers to receive updates from event channel. **If this method isn't called, no updates will be triggered**.
  void registerListeners() {
    _eventChannel.receiveBroadcastStream().listen((dynamic event) {
      Map<String, dynamic> result = Map<String, dynamic>.from(event);
      if (result["buffer"] != null) {
        _bufferedMediaController.add(result["buffer"]);
      }

      if (result["state"] != null) {
        int index = result["state"];
        _playerStateController.add(AudioPlayerState.values[index]);
      }

      if (result["time_elapsed"] != null) {
        double time = result["time_elapsed"];
        _timeElapsedController.add(time);
      }
    }, onError: (dynamic error) {
      _errorController.add(error);
    });
  }

  ///Loads a file in the audio player from a url.
  ///The file will be loaded from the cache if any exists, otherwise it will load it from the network.
  ///The cache entries are generated with the absolute string of the url sent in this method.
  void loadUrl(String url) {
    _channel.invokeMethod('load_from_url', url);
  }

  ///Starts playing
  void play() {
    _channel.invokeMethod('play');
  }

  //Returns the total duration of the current file loaded in the player.
  Future<double> lengthInseconds() async {
    return await _channel.invokeMethod('length_in_seconds');
  }

  ///Pauses the audio player
  void stop() {
    _channel.invokeMethod('stop');
  }

  ///Seeks the player to the received value
  ///This value should go from 0 - 1, representing the percentage of the total duration you want to scroll to. (This is to make it easier to seek with a slider).
  ///For example: If the value sent is 0.5 the player will seek to the middle of the audio file.
  ///The seek function may fail in iOS if the data xwhasn't buffered completely, it will return true if successful.
  Future<bool> seek(double value) async {
    return await _channel.invokeMethod('seek', value);
  }

  ///The FlutterEventChannel 'audio_player_streaming' is registered as a listener to the AudioPlayer class in order to get the player event updates and send them to flutter via events.
  ///This method removes that listener.
  void unregisterListeners() {
    _channel.invokeMethod('unregister_listeners');
  }
}

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.