Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tip: play video file from Directory.data on iOS #134

Closed
ArneTN opened this issue Oct 6, 2023 · 8 comments
Closed

Tip: play video file from Directory.data on iOS #134

ArneTN opened this issue Oct 6, 2023 · 8 comments

Comments

@ArneTN
Copy link

ArneTN commented Oct 6, 2023

This is more a tip, rather than an issue. I struggled a bit with playing video file from Directory.data on iOS, but it turned out it was related to the iOS Simulator.

In my app, I download video files to Directory.data (for offline use). The following code gave me the message "filePath not implemented" in the iOS Simulator. However, it worked perfectly on a real device.

import { Directory, Filesystem,  StatOptions} from '@capacitor/filesystem';
import { Video } from 'src/assets/ts/video';

playVideo(){ 
      //First, check if file exists:
      this.checkIfFileExists("video.mp4", success, error);
  
      function success(uri:string, status:string){      
        let videoPlayer = new Video(uri);//This works on a real device, but does NOT work in the iOS Simulator in XCode.
      }
  
      function error(message:string){
        alert(message);
      }
}

async checkIfFileExists(path:string, success:any, error:any){
    try {
      const options:StatOptions​ = {
        path:path,
        directory: Directory.Data 
      }
  
      await Filesystem.stat(options).then(result => {      
        success(result.uri, result.type + ", " + (result.size/1000) + "kB");
     });

    } catch (e) {
      error(e);
    }
}

Video.ts:

import { CapacitorVideoPlayer, capVideoPlayerIdOptions, capVideoPlayerOptions } from "capacitor-video-player";
import { Capacitor } from '@capacitor/core';

export const setVideoPlayer = async (): Promise<any>=> {
    const platform = Capacitor.getPlatform();
    return {plugin:CapacitorVideoPlayer, platform};
};

export class Video{

    constructor(uri:string){
        this.loadVideo(uri);
    }

    async loadVideo(uri:string){
        let options:capVideoPlayerOptions = {
            mode:"fullscreen",
            url:uri,
            playerId: 'videoPlayerDiv',
            pipEnabled:false,
            displayMode:"sensor",
            chromecast:false
        }

        await CapacitorVideoPlayer.initPlayer(options);

        let playOptions:capVideoPlayerIdOptions = {
            playerId:"videoPlayerDiv"
        }

        await CapacitorVideoPlayer.play(playOptions);
    }

}
@jepiqueau
Copy link
Collaborator

@ArneTN i will have a look to implemented but i am travelling to end next week so not before

@ArneTN
Copy link
Author

ArneTN commented Oct 7, 2023

Thanks. I don't consider it to be a big issue as it works on a real device. However, it would be great if this issue was identified in the docs/readme. I also saw that it was mentioned in a closed issue, but I missed that at first. Thanks for a great plugin!

Regards,
ArneTN

@jepiqueau
Copy link
Collaborator

@ArneTN i come back to you as i start looking at it Can you explain me the displayMode:"sensor" i do not understand "sensor" for me it can be "landscape", "portrait"

@PhantomPainX
Copy link
Contributor

@ArneTN i come back to you as i start looking at it Can you explain me the displayMode:"sensor" i do not understand "sensor" for me it can be "landscape", "portrait"

Maybe he refers to unlocked display mode, basically it can be achieved by not setting the displayMode

@ArneTN
Copy link
Author

ArneTN commented Nov 10, 2023

Sorry, the intention here was orientation based on device orientation (sensor). The documentation says "default: 'portrait'", so my parameter ("sensor") is a leftover from a series of trial-and-error. As PhantomPainX suggests, the correct behavior would probably be achieved by not setting the displayMode at all. I reckon the "sensor" parameter is just ignored in my case.

@jepiqueau
Copy link
Collaborator

@ArneTN @PhantomPainX thanks for the clarification. I will fix this 2 issues in the next release

jepiqueau added a commit that referenced this issue Nov 13, 2023
@jepiqueau
Copy link
Collaborator

@ArneTN @PhantomPainX This has been fixed in 5.0.4-1. Can you check and close the issue after tests

@jepiqueau
Copy link
Collaborator

@ArneTN No reply from you so i assume it works so i close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants