Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import java.io.Serializable
data class ImageMetas(
val imageType: String?,
val imagePackage: String?,
val imagePath: String?
val imagePath: String?,
val bytes: ByteArray?
) : Serializable

data class AudioMetas(
Expand All @@ -21,7 +22,9 @@ fun fetchImageMetas(from: Map<*, *>, suffix: String= "") : ImageMetas {
return ImageMetas(
imagePath = from["song.image$suffix"] as? String,
imageType = from["song.imageType$suffix"] as? String,
imagePackage = from["song.imagePackage$suffix"] as? String
imagePackage = from["song.imagePackage$suffix"] as? String,
bytes = from["song.bytes$suffix"] as? ByteArray

)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import kotlin.coroutines.suspendCoroutine
object ImageDownloader {

suspend fun loadBitmap(context: Context, imageMetas: ImageMetas?) : Bitmap? {
if(imageMetas?.bytes!=null){

val image = BitmapFactory.decodeByteArray(imageMetas!!.bytes, 0, imageMetas!!.bytes!!.size)
return image

}
if (imageMetas?.imageType != null && imageMetas.imagePath != null) {
try {
return getBitmap(context = context,
Expand Down
4 changes: 3 additions & 1 deletion darwin/Classes/Music.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ public class Player : NSObject, AVAudioPlayerDelegate {

func getUrlByType(path: String, audioType: String, assetPackage: String?) -> URL? {
var url : URL

if(path.starts(with:"ipod-library")){
return URL(string: path)
}
if(audioType == "network" || audioType == "liveStream"){
if let u = URL(string: path) {
return u
Expand Down
1 change: 1 addition & 0 deletions example/lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Generated file. Do not edit.
//

// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars

import 'package:assets_audio_player_web/web/assets_audio_player_web.dart';
Expand Down
201 changes: 104 additions & 97 deletions lib/src/playable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ String audioTypeDescription(AudioType audioType) {
}
}

enum ImageType {
network,
file,
asset,
}
enum ImageType { network, file, asset, Uint8List }

String imageTypeDescription(ImageType imageType) {
switch (imageType) {
Expand All @@ -55,6 +51,8 @@ String imageTypeDescription(ImageType imageType) {
return 'file';
case ImageType.asset:
return 'asset';
case ImageType.Uint8List:
return 'uint8list';
}
}

Expand All @@ -64,23 +62,32 @@ class MetasImage {
required this.path,
required this.type,
this.package,
this.cover,
});

final String path;
final ImageType type;
final String? package;
final Uint8List? cover;

const MetasImage.network(this.path)
: type = ImageType.network,
package = null;
package = null,
cover = null;

const MetasImage.asset(
this.path, {
this.package,
}) : type = ImageType.asset;
}) : type = ImageType.asset,
cover = null;

const MetasImage.file(this.path)
: type = ImageType.file,
package = null,
cover = null;
const MetasImage.uint8list(this.cover)
: type = ImageType.Uint8List,
path = 'path',
package = null;

@override
Expand Down Expand Up @@ -158,50 +165,50 @@ class Metas {
}

//Placeholder for future DRM Types
enum DrmType{ token, widevine, fairplay, clearKey }

class DrmConfiguration{
final DrmType drmType;
final String? clearKey;

DrmConfiguration._(this.drmType,{this.clearKey});

factory DrmConfiguration.clearKey({String? clearKey, Map<String,String>? keys}){
if(keys!=null) clearKey = _generate(keys);
var drmConfiguration = DrmConfiguration._(DrmType.clearKey,clearKey: clearKey);
return drmConfiguration;
}


static String _generate(Map<String, String> keys,
{String type = 'temporary'}) {
Map keyMap = <String, dynamic>{'type': type};
keyMap['keys'] = <Map<String, String>>[];
keys.forEach((key, value) => keyMap['keys']
.add({'kty': 'oct', 'kid': _base64(key), 'k': _base64(value)}));
return jsonEncode(keyMap);
}

static String _base64(String source) {
return base64
.encode(_encodeBigInt(BigInt.parse(source, radix: 16)))
.replaceAll('=', '');
}

static final _byteMask = BigInt.from(0xff);

static Uint8List _encodeBigInt(BigInt number) {
var size = (number.bitLength + 7) >> 3;

final result = Uint8List(size);
var pos = size - 1;
for (var i = 0; i < size; i++) {
result[pos--] = (number & _byteMask).toInt();
number = number >> 8;
}
return result;
}
enum DrmType { token, widevine, fairplay, clearKey }

class DrmConfiguration {
final DrmType drmType;
final String? clearKey;

DrmConfiguration._(this.drmType, {this.clearKey});

factory DrmConfiguration.clearKey(
{String? clearKey, Map<String, String>? keys}) {
if (keys != null) clearKey = _generate(keys);
var drmConfiguration =
DrmConfiguration._(DrmType.clearKey, clearKey: clearKey);
return drmConfiguration;
}

static String _generate(Map<String, String> keys,
{String type = 'temporary'}) {
Map keyMap = <String, dynamic>{'type': type};
keyMap['keys'] = <Map<String, String>>[];
keys.forEach((key, value) => keyMap['keys']
.add({'kty': 'oct', 'kid': _base64(key), 'k': _base64(value)}));
return jsonEncode(keyMap);
}

static String _base64(String source) {
return base64
.encode(_encodeBigInt(BigInt.parse(source, radix: 16)))
.replaceAll('=', '');
}

static final _byteMask = BigInt.from(0xff);

static Uint8List _encodeBigInt(BigInt number) {
var size = (number.bitLength + 7) >> 3;

final result = Uint8List(size);
var pos = size - 1;
for (var i = 0; i < size; i++) {
result[pos--] = (number & _byteMask).toInt();
number = number >> 8;
}
return result;
}
}

class Audio extends Playable {
Expand All @@ -219,17 +226,17 @@ class Audio extends Playable {

Map<String, String>? get networkHeaders => _networkHeaders;

Audio._({
required this.path,
required this.audioType,
this.package,
this.cached,
this.playSpeed,
this.pitch,
Map<String, String>? headers,
Metas? metas,
this.drmConfiguration
}) : _metas = metas ?? Metas(),
Audio._(
{required this.path,
required this.audioType,
this.package,
this.cached,
this.playSpeed,
this.pitch,
Map<String, String>? headers,
Metas? metas,
this.drmConfiguration})
: _metas = metas ?? Metas(),
_networkHeaders = headers;

Audio(
Expand All @@ -256,27 +263,25 @@ class Audio extends Playable {
cached = false,
_metas = metas ?? Metas();

Audio.network(
this.path, {
Metas? metas,
Map<String, String>? headers,
this.cached = false,
this.playSpeed,
this.pitch,
this.drmConfiguration
}) : audioType = AudioType.network,
Audio.network(this.path,
{Metas? metas,
Map<String, String>? headers,
this.cached = false,
this.playSpeed,
this.pitch,
this.drmConfiguration})
: audioType = AudioType.network,
package = null,
_networkHeaders = headers,
_metas = metas ?? Metas();

Audio.liveStream(
this.path, {
Metas? metas,
this.playSpeed,
this.pitch,
Map<String, String>? headers,
this.drmConfiguration
}) : audioType = AudioType.liveStream,
Audio.liveStream(this.path,
{Metas? metas,
this.playSpeed,
this.pitch,
Map<String, String>? headers,
this.drmConfiguration})
: audioType = AudioType.liveStream,
package = null,
_networkHeaders = headers,
cached = false,
Expand Down Expand Up @@ -327,26 +332,24 @@ class Audio extends Playable {
});
}

Audio copyWith({
String? path,
String? package,
AudioType? audioType,
Metas? metas,
double? playSpeed,
Map<String, String>? headers,
bool? cached,
DrmConfiguration? drmConfiguration
}) {
Audio copyWith(
{String? path,
String? package,
AudioType? audioType,
Metas? metas,
double? playSpeed,
Map<String, String>? headers,
bool? cached,
DrmConfiguration? drmConfiguration}) {
return Audio._(
path: path ?? this.path,
package: package ?? this.package,
audioType: audioType ?? this.audioType,
metas: metas ?? _metas,
headers: headers ?? _networkHeaders,
playSpeed: playSpeed ?? this.playSpeed,
cached: cached ?? this.cached,
drmConfiguration: drmConfiguration??this.drmConfiguration
);
path: path ?? this.path,
package: package ?? this.package,
audioType: audioType ?? this.audioType,
metas: metas ?? _metas,
headers: headers ?? _networkHeaders,
playSpeed: playSpeed ?? this.playSpeed,
cached: cached ?? this.cached,
drmConfiguration: drmConfiguration ?? this.drmConfiguration);
}
}

Expand Down Expand Up @@ -477,6 +480,10 @@ void writeAudioImageMetasInto(
Map<String, dynamic> params, MetasImage? metasImage,
{String suffix = ''}) {
if (metasImage != null) {
if (metasImage.cover?.isNotEmpty == true) {
params.addIfNotNull('song.bytes$suffix', metasImage.cover);
}

params['song.image$suffix'] = metasImage.path;
params['song.imageType$suffix'] = imageTypeDescription(metasImage.type);
params.addIfNotNull('song.imagePackage$suffix', metasImage.package);
Expand Down