2

播放器 mp3 给出错误:

RTP Handler internal error: javax.media.ControllerErrorEvent[source=com.sun.medi
a.content.unknown.Handler@baf4ae,message=Internal module com.sun.media.BasicRend
ererModule@197f158: failed to handle a data format change!]


i m running 
server as:java MediaConverterExample rtp://rajneesh-pc:49150/audio   Dead_End.mp3

client as:java PlayerExample rtp://rajneesh-pc:49150/audio

这是服务器端代码

    import javax.media.*;
     import java.io.File;
     import java.io.IOException;
          import java.net.URL;
            import java.net.MalformedURLException;
          import javax.media.protocol.*;
          import javax.media.format.AudioFormat;


      import javax.swing.*;
     import java.awt.*;
         import java.awt.event.*;


         class MediaConvertion
      {
         private MediaLocator mediaLocator = null;

       private DataSink dataSink = null;

      private Processor mediaProcessor = null;

      private static final Format[] FORMATS = new Format[]                          {                   new AudioFormat(AudioFormat.MPEG_RTP)};


               private static final ContentDescriptor CONTENT_DESCRIPTOR =new    ContentDescriptor  (ContentDescriptor.RAW_RTP);


           public MediaConvertion(String url)throws IOException,NoProcessorException,   CannotRealizeException, NoDataSinkException, NoDataSinkException
 {
mediaLocator=new MediaLocator(url);

}

            public void setDataSource(DataSource ds) throws      IOException,NoProcessorException,                      CannotRealizeException, NoDataSinkException {

             mediaProcessor = Manager.createRealizedProcessor(new ProcessorModel(ds, FORMATS,                               CONTENT_DESCRIPTOR));
            dataSink = Manager.createDataSink(mediaProcessor.getDataOutput(),mediaLocator);
     }


       public void startTransmitting() throws IOException {
  mediaProcessor.start();
      dataSink.open();
        dataSink.start();
        }


          public void stopTransmitting() throws IOException {
        dataSink.stop();
      dataSink.close();
       mediaProcessor.stop();
        mediaProcessor.close();
         }
                }

    public class MediaConverterExample extends Frame implements ActionListener
      {

Button st_stream;
static MediaConvertion mdcon;

    public static void main(String args[])throws IOException,NoProcessorException, CannotRealizeException, NoDataSinkException,MalformedURLException,NoDataSourceException
     {
   Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
         Format input2 = new AudioFormat(AudioFormat.MPEG);
         Format output = new AudioFormat(AudioFormat.LINEAR);
         PlugInManager.addPlugIn(
       "com.sun.media.codec.audio.mp3.JavaDecoder",
       new Format[]{input1, input2},
      new Format[]{output},
      PlugInManager.CODEC
   );
    File mediaFile = new File(args[1]);
    DataSource source = Manager.createDataSource(new MediaLocator(mediaFile.toURL()));
    mdcon=new MediaConvertion(args[0]);
     mdcon.setDataSource(source);
new MediaConverterExample();
    }

public MediaConverterExample()
{
    st_stream=new Button("Start Streaming");
    add(st_stream);
    st_stream.addActionListener(this);
    setVisible(true);
    setSize(200,300);

}
public void actionPerformed(ActionEvent ae)
{   
    try
    {
    mdcon.startTransmitting();
    }
    catch(Exception e){
    }
   }
   }

这是客户端代码

import javax.media.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import javax.media.format.*;

public class PlayerExample extends JFrame implements ActionListener
{
Button play;
 SimpleAudioPlayer sap;

    PlayerExample(String playFile) throws IOException,NoPlayerException, CannotRealizeException
    {
        sap=new SimpleAudioPlayer(new MediaLocator(playFile));
        setLayout(new BorderLayout());
        //add(sap.VideoComponent(),BorderLayout.CENTER);
        //add(sap.AudioComponent(),BorderLayout.WEST);
        //add(sap.ControlComponent(),BorderLayout.NORTH);
        add(play=new Button("play"),BorderLayout.SOUTH);
        play.addActionListener(this);
        setSize(200,300);
        setVisible(true);       
    }

    public void actionPerformed(ActionEvent ae)
    {

    sap.play();     

    }
     public static void main(String args[])throws IOException,NoPlayerException, CannotRealizeException
    {
        Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
                Format input2 = new AudioFormat(AudioFormat.MPEG);
              Format output = new AudioFormat(AudioFormat.LINEAR);
             PlugInManager.addPlugIn(
               "com.sun.media.codec.audio.mp3.JavaDecoder",
              new Format[]{input1, input2},
           new Format[]{output},
             PlugInManager.CODEC
               );

    new PlayerExample(args[0]);
       }
          }

class SimpleAudioPlayer {

private Player videoPlayer = null;

public SimpleAudioPlayer(MediaLocator ml) throws IOException, NoPlayerException, CannotRealizeException  {

                        videoPlayer = Manager.createRealizedPlayer(ml);
                        }


public void play() {
                        //videoPlayer.deallocate();
                        videoPlayer.start();
                        }
public void stop() {
                        videoPlayer.stop();

                        }
       public Component VideoComponent(){
                                return videoPlayer.getVisualComponent();
                        }
     public Component  ControlComponent(){
                        return videoPlayer.getControlPanelComponent();          
                        }
public Component AudioComponent(){
                        return videoPlayer.getGainControl().getControlComponent();
                        }


        }

请帮助我尽我所能。请告知我可能遗漏的任何其他细节,服务器运行良好,但客户端在创建播放器时阻塞。我使用的音频格式是 MPEG_RAW。急切地寻找答案,在此先感谢。

4

1 回答 1

2

解决了......

我在看甲骨文论坛时想到了

改变

  AudioFormat.MPEG_RTP  to AudioFormat.DVI_RTP

不要问mp3为什么不起作用的原因。我尽我所能。

请告诉我为什么以前没有工作。

于 2013-04-21T02:22:12.203 回答