package com.uvigo.mhp.mediaPlayer;

import javax.media.*;

class MediaScrollBarThread extends Thread
{
    MediaScrollBar sb;
    Player p;
    boolean flag;
    
    MediaScrollBarThread(MediaScrollBar sb, Player p)
    {
        this.sb=sb;
        this.p=p;
        flag=false;
    }
    
    public synchronized void run()
    {
        while(true)
        {
            if (!flag)
            {
                try
                {
                    wait();
                }
                catch (Exception e)
                {
                    System.out.println(e);
                }
            }
            int pos=(int)((double) p.getMediaTime().getNanoseconds()/(double) p.getDuration().getNanoseconds()*100);
            sb.setValue(pos);
            try
            {
                wait(500);
            }
            catch (Exception e)
            {
                System.out.println(e);
            }
        }
    }
    
    public synchronized void off()
    {
        flag=false;
    }
    
    public synchronized void on()
    {
        flag=true;
        notify();
    }
}