Search code examples
cordovaionic-frameworkrtsplive-streaming

How to play rtsp live video in ionic 2?


I am unable to get a suitable plugin to play rtsp video in my ionic app.tried CordovaStreamingMedia,cordova-rtsp but with no success.Pls help


Solution

  • install this plugin in ionic project.

    ionic cordova plugin add cordova-plugin-streaming-media
    npm install --save @ionic-native/streaming-media
    

    =========================== .ts =================================

    import { NavController, ToastController } from 'ionic-angular';
    import { StreamingMedia, StreamingVideoOptions, StreamingAudioOptions } from '@ionic-native/streaming-media';
    
    constructor(public navCtrl: NavController,
              public toastCtrl: ToastController,
              private streamingMedia: StreamingMedia) { }
    
    startVideo(){
    let options: StreamingVideoOptions = {
      successCallback: () => { this.tost('Video played'); },
      errorCallback: (e) => { this.tost(JSON.stringify(e)); },
      orientation: 'landscape',
    // orientation: 'portrait'
    };
    
    this.streamingMedia.playVideo(**'YOUR_LIVE_STREAMING_URL'**, options);
    }
    
    tost(message){
    
    let toast = this.toastCtrl.create({
      message: message,
      duration: 3000
    });
    toast.present();
    }
    

    ========================= HTML ======================

    <ion-card>
    <button ion-button (click)="startVideo()">Start Video</button>
    </ion-card>