Skip to content

Commit

Permalink
fix: Not use exception handling and Not throw exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Korilakkuma committed Jan 28, 2023
1 parent 7f1f618 commit a7bf4b2
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/MediaModule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ export class MediaModule extends SoundModule {
.then(() => {
this.start(this.media?.currentTime ?? 0);
})
.catch(() => {
throw new Error('Autoplay is failed');
.catch((error: Error) => {
if (this.listeners.error) {
this.listeners.error(error);
}
});
}

Expand Down Expand Up @@ -214,36 +216,30 @@ export class MediaModule extends SoundModule {
}
}

try {
if (mimeType) {
// Audio Streaming
if (!MediaSource || !MediaSource.isTypeSupported(mimeType)) {
throw new Error('This Browser does not support `MediaSource` or MIME type');
}
if (mimeType) {
// Audio Streaming
if (!MediaSource || !MediaSource.isTypeSupported(mimeType)) {
return this;
}

this.media.removeAttribute('src');
this.media.removeAttribute('src');

this.media.load();
this.media.load();

this.mediaSource = new MediaSource();
this.media.src = window.URL.createObjectURL(this.mediaSource);
this.mimeType = mimeType;
this.file = src;
this.mediaSource = new MediaSource();
this.media.src = window.URL.createObjectURL(this.mediaSource);
this.mimeType = mimeType;
this.file = src;

this.mediaSource.addEventListener('sourceopen', this.onSourceOpen, false);
this.mediaSource.addEventListener('sourceended', this.onSourceEnded, false);
this.mediaSource.addEventListener('sourceclose', this.onSourceClose, false);
} else if (src.startsWith('blob:') || (this.ext === '')) {
// Object URL or file name
this.media.src = src;
} else {
// file name (except extension)
this.media.src = `${src}.${this.ext}`;
}
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
}
this.mediaSource.addEventListener('sourceopen', this.onSourceOpen, false);
this.mediaSource.addEventListener('sourceended', this.onSourceEnded, false);
this.mediaSource.addEventListener('sourceclose', this.onSourceClose, false);
} else if (src.startsWith('blob:') || (this.ext === '')) {
// Object URL or file name
this.media.src = src;
} else {
// file name (except extension)
this.media.src = `${src}.${this.ext}`;
}

return this;
Expand Down

0 comments on commit a7bf4b2

Please sign in to comment.