tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
2397
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    MasterHimself MasterHimself ist offline Mitglied Bronze
    Registriert seit
    Oct 2005
    Beiträge
    35
    Ich habe ein schwerwiegendes Problem,

    ich nutze die Mp3spi Klassen, um in Java einen MP3 Player wie Winamp zu bauen,
    das einzigste was mir noch fehlt, ist eine Methode im Player, die die MP3 Datei
    an eine bestimmte Position setzt. Ich habe keine Ideen wie ich das anstellen soll,
    goggle hat mir auch nicht geholfen...

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    
    package mediaplayer.player;
     
    import mediaplayer.playlist.*;
    import java.io.*;
    import javax.sound.sampled.*;
     
    public class Player extends Thread{
        private static final long serialVersionUID = 100;
     
    private static File track;
    private static AudioInputStream mp3Stream;
    private static AudioInputStream wavStream;
    private static AudioFormat baseFormat;
    private static AudioFormat decodedFormat;
    private static SourceDataLine line;
    private static boolean pause = false;
    private static boolean stopped = true;
    private static boolean started = false;
    private static double time;
    private static FloatControl settings;
    private static BooleanControl advsettings;
     
     
        
        public static void startbreakPlay(){
            if(pause){
                pause = false;
            }
            else{
            if(stopped){
                stopped = false;
                initPlay();
                if(! started){
                    started = true;
                    Player p1 = new Player();
                    p1.start();
                }
            }
            else{
                pause = true;
            }
            }
        }
        
        public static void stopPlay(){
            if(! stopped){
                stopped = true;
            }
        }
        
        public static void goForward(){
            stopPlay();
            Playlist.goForward();
            startbreakPlay();
        }
        
        public static void goBackward(){
            stopPlay();
            Playlist.goBackward();
            startbreakPlay();
        }
        
        public static String getPosition(){
            long tmp = Math.round(100*time);
            return String.valueOf(tmp/100.0d);
        }
        
        public static double getBalance(){
            settings = (FloatControl) line.getControl(FloatControl.Type.BALANCE);
            return settings.getValue();
        }
        
        public static void setBalance(double value){
            settings = (FloatControl) line.getControl(FloatControl.Type.BALANCE);
            settings.setValue((float)value);
        }
        
        public static boolean getMute(){
            advsettings = (BooleanControl) line.getControl(BooleanControl.Type.MUTE);
            return advsettings.getValue();
        }
        
        public static void setMute(boolean value){
            advsettings = (BooleanControl) line.getControl(BooleanControl.Type.MUTE);
            advsettings.setValue(value);
        }
        
        public static double getMasterGain(){
            settings = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
            return settings.getValue();
        }
        
        public static void setMasterGain(double value){
            settings = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
            settings.setValue((float)value);
        }
        
        public void run(){
            try{
            byte[] data = new byte[4096];
            int nBytesRead = 0;
            if(line != null){
                while(nBytesRead != -1){
                    while(pause) Thread.sleep(10);
                    while(stopped) Thread.sleep(10);
                    time = line.getMicrosecondPosition()/1000000.0d;
                    nBytesRead = wavStream.read(data,0,data.length);
                    line.write(data,0,nBytesRead);
                }
            }
            }
            catch(Exception ex){}
            started = false;
            goForward();
        }
        
        private static void initPlay(){
            try{
            track = new File(Playlist.getCurrentEntry());
            mp3Stream = AudioSystem.getAudioInputStream(track);
            
            baseFormat = mp3Stream.getFormat();
            decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                                            baseFormat.getSampleRate(),
                                            16,
                                            baseFormat.getChannels(),
                                            baseFormat.getChannels()*2,
                                            baseFormat.getSampleRate(),
                                            false);
            
            wavStream = AudioSystem.getAudioInputStream(decodedFormat, mp3Stream);
            line = getLine(decodedFormat);
            line.start();
            }
            catch(Exception ex){}
        }
        
        private static SourceDataLine getLine(AudioFormat format) throws LineUnavailableException{
            SourceDataLine tmp = null;
            DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
            tmp = (SourceDataLine) AudioSystem.getLine(info);
            tmp.open(format);
            return tmp;
        }
    }

    Wenn jemand eine Idee oder auch nur einen Ansatz für das Problem weiß, wäre ich sehr
    dankbar.
    Geändert von MasterHimself (25.10.05 um 01:20 Uhr)
     

  2. #2
    Registriert seit
    Apr 2007
    Beiträge
    209
    Hi,

    ich weiß, das Thema ist schon ziemlich alt aber ich würd gerne wissen ob du eine Lösung gefunden hast und wenn ja ob du die mal posten kannst, daich gerade bei demselben problem sitze..

    Thx
    Chriz
     

Ähnliche Themen

  1. Seek unter CLR
    Von Olaf Lehmann im Forum VisualStudio & MFC
    Antworten: 9
    Letzter Beitrag: 17.07.10, 12:59
  2. seek time in flv
    Von TraphiX im Forum Flash Plattform
    Antworten: 1
    Letzter Beitrag: 27.08.09, 11:47
  3. Recordset auf Datenbank und das Problem mit .SEEK
    Von Sonie im Forum Visual Basic 6.0
    Antworten: 0
    Letzter Beitrag: 26.07.04, 15:01
  4. seek in textdateien
    Von savar im Forum Delphi, Kylix, Pascal
    Antworten: 2
    Letzter Beitrag: 17.06.04, 15:56
  5. Live Stream Converter (Shoutcast Stream)?
    Von plusfunenf im Forum Linux & Unix
    Antworten: 1
    Letzter Beitrag: 22.04.04, 14:45