ionic 2 cordova-plugin-media buffers mp3 files before streaming

520 views Asked by At

I am new to cordova-media-plugin, I am using it in Ionic 2 App to stream mp3 files from the internet. But I noticed, files are not being streamed directly, they are downloaded locally first, then playing starts.

I follow the below tutorial in Ionic Native documentation:

https://ionicframework.com/docs/native/media/

Below is the code which I am using to create the MediaObject:

export class CLesson{
    name: string;
    id: number;
    order: number;
    url: string;
    isPlaying: boolean = false;
    audioFile: MediaObject = null;
    listeningSeries: LessonStateChangeListener = null;

    constructor(beCLesson : BeCLesson, listeningSeries : LessonStateChangeListener = null)
    {
        this.name = beCLesson.name;
        this.id = beCLesson.id;
        this.order = beCLesson.order;
        this.url = beCLesson.url;

        if(listeningSeries != null)
            this.listeningSeries = listeningSeries;
    }

    initAudioFile(mediaPlugin : MediaPlugin)
    {
        const onStatusUpdate = (status) => console.log(status);
        const onSuccess = () => console.log('Action is successful.');
        const onError = (error) => console.error(error.message);

        if(this.audioFile == null)
            this.audioFile = mediaPlugin.create(this.url, onStatusUpdate, onSuccess, onError);
    }

    play()
    {
        // Notify the series that this lesson started playing
        if(this.listeningSeries != null)
            this.listeningSeries.onPlayStateChange(this);

        if(this.audioFile != null)
        {   
            this.audioFile.play();
            this.isPlaying = true;
        }
    }

    pause()
    {
        // Notify the series that this lesson paused playing
        if(this.listeningSeries != null)
            this.listeningSeries.onPauseStateChange(this);

        if(this.audioFile != null)
        {   
            this.audioFile.pause();
            this.isPlaying = false;
        }
    }

    stop()
    {
        // Notify the series that this lesson paused playing
        if(this.listeningSeries != null)
            this.listeningSeries.onStopStateChange(this);

        if(this.audioFile != null)
        {
            this.audioFile.stop();   
            this.isPlaying = false;
        }
    }
}

Is this issue normal? ... how can I stream mp3 files from the internet without downloading them locally?

Thanks,

0

There are 0 answers