refactor media information classes

pull/585/head
Taner Sener 3 years ago
parent 99cae3bcfc
commit c43fed6901
  1. 16
      react-native/src/index.d.ts
  2. 105
      react-native/src/index.js

@ -321,7 +321,7 @@ declare module 'ffmpeg-kit-react-native' {
export class MediaInformation { export class MediaInformation {
static readonly KEY_MEDIA_PROPERTIES: string; static readonly KEY_FORMAT_PROPERTIES: string;
static readonly KEY_FILENAME: string; static readonly KEY_FILENAME: string;
static readonly KEY_FORMAT: string; static readonly KEY_FORMAT: string;
static readonly KEY_FORMAT_LONG: string; static readonly KEY_FORMAT_LONG: string;
@ -357,9 +357,15 @@ declare module 'ffmpeg-kit-react-native' {
getNumberProperty(key: string): number; getNumberProperty(key: string): number;
getProperties(key: string): Record<string, any>; getProperty(key: string): any;
getMediaProperties(): Record<string, any>; getStringFormatProperty(key: string): string;
getNumberFormatProperty(key: string): number;
getFormatProperty(key: string): any;
getFormatProperties(): Record<string, any>;
getAllProperties(): Record<string, any>; getAllProperties(): Record<string, any>;
@ -591,7 +597,7 @@ declare module 'ffmpeg-kit-react-native' {
getNumberProperty(key): number; getNumberProperty(key): number;
getProperties(key): Record<string, any>; getProperty(key): any;
getAllProperties(): Record<string, any>; getAllProperties(): Record<string, any>;
@ -627,7 +633,7 @@ declare module 'ffmpeg-kit-react-native' {
getNumberProperty(key): number; getNumberProperty(key): number;
getProperties(key): Record<string, any>; getProperty(key): any;
getAllProperties(): Record<string, any>; getAllProperties(): Record<string, any>;

@ -2438,7 +2438,7 @@ export class Log {
*/ */
export class MediaInformation { export class MediaInformation {
static KEY_MEDIA_PROPERTIES = "format"; static KEY_FORMAT_PROPERTIES = "format";
static KEY_FILENAME = "filename"; static KEY_FILENAME = "filename";
static KEY_FORMAT = "format_name"; static KEY_FORMAT = "format_name";
static KEY_FORMAT_LONG = "format_long_name"; static KEY_FORMAT_LONG = "format_long_name";
@ -2460,7 +2460,7 @@ export class MediaInformation {
* @return media file name * @return media file name
*/ */
getFilename() { getFilename() {
return this.getStringProperty(MediaInformation.KEY_FILENAME); return this.getStringFormatProperty(MediaInformation.KEY_FILENAME);
} }
/** /**
@ -2469,7 +2469,7 @@ export class MediaInformation {
* @return media format * @return media format
*/ */
getFormat() { getFormat() {
return this.getStringProperty(MediaInformation.KEY_FORMAT); return this.getStringFormatProperty(MediaInformation.KEY_FORMAT);
} }
/** /**
@ -2478,7 +2478,7 @@ export class MediaInformation {
* @return media long format * @return media long format
*/ */
getLongFormat() { getLongFormat() {
return this.getStringProperty(MediaInformation.KEY_FORMAT_LONG); return this.getStringFormatProperty(MediaInformation.KEY_FORMAT_LONG);
} }
/** /**
@ -2487,7 +2487,7 @@ export class MediaInformation {
* @return media duration in "seconds.microseconds" format * @return media duration in "seconds.microseconds" format
*/ */
getDuration() { getDuration() {
return this.getStringProperty(MediaInformation.KEY_DURATION); return this.getStringFormatProperty(MediaInformation.KEY_DURATION);
} }
/** /**
@ -2496,7 +2496,7 @@ export class MediaInformation {
* @return media start time in milliseconds * @return media start time in milliseconds
*/ */
getStartTime() { getStartTime() {
return this.getStringProperty(MediaInformation.KEY_START_TIME); return this.getStringFormatProperty(MediaInformation.KEY_START_TIME);
} }
/** /**
@ -2505,7 +2505,7 @@ export class MediaInformation {
* @return media size in bytes * @return media size in bytes
*/ */
getSize() { getSize() {
return this.getStringProperty(MediaInformation.KEY_SIZE); return this.getStringFormatProperty(MediaInformation.KEY_SIZE);
} }
/** /**
@ -2514,7 +2514,7 @@ export class MediaInformation {
* @return media bitrate in kb/s * @return media bitrate in kb/s
*/ */
getBitrate() { getBitrate() {
return this.getStringProperty(MediaInformation.KEY_BIT_RATE); return this.getStringFormatProperty(MediaInformation.KEY_BIT_RATE);
} }
/** /**
@ -2523,7 +2523,7 @@ export class MediaInformation {
* @return tags dictionary * @return tags dictionary
*/ */
getTags() { getTags() {
return this.getProperties(MediaInformation.KEY_TAGS); return this.getFormatProperty(MediaInformation.KEY_TAGS);
} }
/** /**
@ -2571,58 +2571,103 @@ export class MediaInformation {
} }
/** /**
* Returns the media property associated with the key. * Returns the property associated with the key.
* *
* @param key property key * @param key property key
* @return media property as string or undefined if the key is not found * @return property as string or undefined if the key is not found
*/ */
getStringProperty(key) { getStringProperty(key) {
let mediaProperties = this.getMediaProperties(); let allProperties = this.getAllProperties();
if (mediaProperties !== undefined) { if (allProperties !== undefined) {
return mediaProperties[key]; return allProperties[key];
} else { } else {
return undefined; return undefined;
} }
} }
/** /**
* Returns the media property associated with the key. * Returns the property associated with the key.
* *
* @param key property key * @param key property key
* @return media property as number or undefined if the key is not found * @return property as number or undefined if the key is not found
*/ */
getNumberProperty(key) { getNumberProperty(key) {
let mediaProperties = this.getMediaProperties(); let allProperties = this.getAllProperties();
if (mediaProperties !== undefined) { if (allProperties !== undefined) {
return mediaProperties[key]; return allProperties[key];
} else { } else {
return undefined; return undefined;
} }
} }
/** /**
* Returns the media properties associated with the key. * Returns the property associated with the key.
* *
* @param key properties key * @param key property key
* @return media properties as an object or undefined if the key is not found * @return property as an object or undefined if the key is not found
*/ */
getProperties(key) { getProperty(key) {
let mediaProperties = this.getMediaProperties(); let allProperties = this.getAllProperties();
if (mediaProperties !== undefined) { if (allProperties !== undefined) {
return mediaProperties[key]; return allProperties[key];
} else {
return undefined;
}
}
/**
* Returns the format property associated with the key.
*
* @param key property key
* @return format property as string or undefined if the key is not found
*/
getStringFormatProperty(key) {
let formatProperties = this.getFormatProperties();
if (formatProperties !== undefined) {
return formatProperties[key];
} else {
return undefined;
}
}
/**
* Returns the format property associated with the key.
*
* @param key property key
* @return format property as number or undefined if the key is not found
*/
getNumberFormatProperty(key) {
let formatProperties = this.getFormatProperties();
if (formatProperties !== undefined) {
return formatProperties[key];
} else {
return undefined;
}
}
/**
* Returns the format property associated with the key.
*
* @param key property key
* @return format property as an object or undefined if the key is not found
*/
getFormatProperty(key) {
let formatProperties = this.getFormatProperties();
if (formatProperties !== undefined) {
return formatProperties[key];
} else { } else {
return undefined; return undefined;
} }
} }
/** /**
* Returns all media properties. * Returns all format properties defined.
* *
* @returns an object where media properties can be accessed by property names * @returns an object where format properties can be accessed by property names
*/ */
getMediaProperties() { getFormatProperties() {
if (this.#allProperties !== undefined) { if (this.#allProperties !== undefined) {
return this.#allProperties.format; return this.#allProperties[MediaInformation.KEY_FORMAT_PROPERTIES];
} else { } else {
return undefined; return undefined;
} }

Loading…
Cancel
Save