Skip to content

Commit

Permalink
Plugin: Make global variables & functions private. Fix #18
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Dec 4, 2021
1 parent 862cccc commit 91b54ba
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/flutter_media_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/services.dart';

var kChannel = const MethodChannel('flutter_media_metadata');
var _kChannel = const MethodChannel('flutter_media_metadata');

class MetadataRetriever {
static Future<Metadata> fromFile(File file) async {
return Metadata.fromMap(await kChannel
return Metadata.fromMap(await _kChannel
.invokeMethod('MetadataRetriever', {'filePath': file.path}));
}
}
Expand Down Expand Up @@ -53,16 +53,16 @@ class Metadata {
: null,
albumName: map['metadata']['albumName'],
albumArtistName: map['metadata']['albumArtistName'],
trackNumber: parse(map['metadata']['trackNumber']),
albumLength: parse(map['metadata']['albumLength']),
year: parse(map['metadata']['year']),
trackNumber: _parse(map['metadata']['trackNumber']),
albumLength: _parse(map['metadata']['albumLength']),
year: _parse(map['metadata']['year']),
genre: map['genre'],
authorName: map['metadata']['authorName'],
writerName: map['metadata']['writerName'],
discNumber: parse(map['metadata']['discNumber']),
discNumber: _parse(map['metadata']['discNumber']),
mimeType: map['metadata']['mimeType'],
trackDuration: parse(map['metadata']['trackDuration']),
bitrate: parse(map['metadata']['bitrate']),
trackDuration: _parse(map['metadata']['trackDuration']),
bitrate: _parse(map['metadata']['bitrate']),
albumArt: map['albumArt'],
);

Expand All @@ -87,14 +87,18 @@ class Metadata {
String toString() => JsonEncoder.withIndent(' ').convert(toMap());
}

int? parse(String? string) {
if (string == null) return null;
try {
int? _parse(dynamic value) {
if (value == null) return null;
if (value is int)
return value;
else if (value is String) {
try {
return int.parse(string);
} catch (exception) {
return int.parse(string.split('/').first);
}
} catch (exception) {}
try {
return int.parse(value);
} catch (exception) {
return int.parse(value.split('/').first);
}
} catch (exception) {}
}
return null;
}

0 comments on commit 91b54ba

Please sign in to comment.