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

Why ASS.resize() doesnt work? #34

Closed
wraith4081 opened this issue Aug 27, 2022 · 3 comments
Closed

Why ASS.resize() doesnt work? #34

wraith4081 opened this issue Aug 27, 2022 · 3 comments

Comments

@wraith4081
Copy link

ASS is exactly the library I want, but it doesn't work even though I call the resize function when the screen size changes or my player is full screen.

ass = new ASS(text, video, {
    container: document.querySelector('.ASS-container'),
    resampling: 'video_height',
});
window.addEventListener('resize', () => {
    /* My own try, but this either doesnt work
    const ASSContainer = document.querySelector('.ASS-container');
    const width = video.offsetWidth + 'px';
    const height = video.offsetHeight + 'px';
    ASSContainer.style.width = width;
    ASSContainer.style.height = height;
    [...ASSContainer.children].forEach(el => {
        el.style.width = width;
        el.style.height = height;
    });
    */
    
    ass.resize();
 });
@wraith4081
Copy link
Author

Problem solved with:

fullscreen.addEventListener('click', () => {
  const src = document.querySelector('.subtitleElement.active').getAttribute('src');
  if (src.endsWith('.ass')) {
    fetch(src).then(res => res.text()).then(text => {
      assHardStop()
      ass = new ASS(text, video, {
        container: document.querySelector('.ASS-container'),
        resampling: 'video_height',
      });fullsc
      assHardStop = ass.destroy.bind(ass);
    }).catch(err => {
      console.log(err);
    });
  }

@wraith4081
Copy link
Author

Problem solved with:

var assHardStop = () => {};
...
fullscreen.addEventListener('click', () => {
  const src = document.querySelector('.subtitleElement.active').getAttribute('src');
  if (src.endsWith('.ass')) {
    fetch(src).then(res => res.text()).then(text => {
      assHardStop()
      ass = new ASS(text, video, {
        container: document.querySelector('.ASS-container'),
        resampling: 'video_height',
      });
      assHardStop = ass.destroy.bind(ass);
    }).catch(err => {
      console.log(err);
    });
  }

But you must add line when you destroy and recreate the ASS class

assHardStop = ass.destroy.bind(ass);

@weizhenye
Copy link
Owner

ass.resize() should be called when the container size is changed. You can try it in https://ass.js.org/ and find the source code in https://github.com/weizhenye/ASS/blob/gh-pages/main.js#L75-L86

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

2 participants