All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.monte.media.DefaultMovie Maven / Gradle / Ivy

The newest version!

package org.monte.media;

import java.io.IOException;
import org.monte.media.math.Rational;


public class DefaultMovie extends AbstractMovie {
    private MovieReader reader;
    private Rational playhead;
    private Rational in;
    private Rational out;

    @Override
    public MovieReader getReader() {
        return reader;
    }

    public void setReader(MovieReader reader) {
        this.reader = reader;
        try {
            this.out=reader.getDuration();
        } catch (IOException ex) {
            InternalError ie= new InternalError("Can't read duration.");
            ie.initCause(ex);
            throw ie;
        }
        this.playhead=new Rational(0,1);
        this.in=new Rational(0,1);
    }



    @Override
    public Rational getDuration() {
        try {
        return reader.getDuration();
        } catch (IOException ex) {
            InternalError ie= new InternalError("Can't read duration.");
            ie.initCause(ex);
            throw ie;
        }
    }


    @Override
    public Rational getInsertionPoint() {
        return playhead;
    }

    @Override
    public void setInsertionPoint(Rational newValue) {
        Rational oldValue=this.playhead;
        this.playhead = newValue;
        firePropertyChange(PLAYHEAD_PROPERTY, oldValue, newValue);
    }

    @Override
    public Rational getSelectionStart() {
        return in;
    }

    @Override
    public void setSelectionStart(Rational newValue) {
        Rational oldValue=in;
        this.in = newValue;
        firePropertyChange(IN_PROPERTY, oldValue, newValue);
    }

    @Override
    public Rational getSelectionEnd() {
        return out;
    }

    @Override
    public void setSelectionEnd(Rational newValue) {
        Rational oldValue=out;
        this.out = newValue;
        firePropertyChange(OUT_PROPERTY, oldValue, newValue);
    }



    @Override
    public long timeToSample(int track, Rational time) {
        try {
            return reader.timeToSample(track, time);
        } catch (IOException ex) {
            return 0;
        }
    }
    @Override
    public Rational sampleToTime(int track, long sample) {
        try {
            return reader.sampleToTime(track, sample);
        } catch (IOException ex) {
            return new Rational(0);
        }
    }

    @Override
    public int getTrackCount() {
        try {
        return reader.getTrackCount();
        } catch (IOException e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public Format getFormat(int track) {
        try {
            return reader.getFormat(track);
        } catch (IOException ex) {
           return null;
        }
    }

    @Override
    public Format getFileFormat() {
        try {
            return reader.getFileFormat();
        } catch (IOException ex) {
            return null;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy