powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / JMF MP3
4 сообщений из 4, страница 1 из 1
JMF MP3
    #33155446
Dima Yermak
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Помогите решить проблему.
Надо в приложении проигрывать mp3.
на данный момент wav работает но надо mp3.
Код
Код: plaintext
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.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
 import  javax.media.*;
 import  javax.swing.*;
 import  java.awt.*;
 import  java.awt.event.ActionEvent;
 import  java.awt.event.ActionListener;
 import  java.io.IOException;
 import  java.net.MalformedURLException;
 import  java.net.URL;

/**
 * User: dima
 * Date: 07.07.2005
 * Time: 16:07:21
 */
 public   class  Main  extends  JFrame  implements  ControllerListener {
    Main main;
     public  Player player =  null ;
    Component visualComponent =  null ;
    Component controlComponent =  null ;
    Component progressBar =  null ;
     boolean  firstTime = true;
     long  CachingSize = 0L;
     int  controlPanelHeight =  0 ;
     int  videoWidth =  0 ;
     int  videoHeight =  0 ;
    JPanel panel =  new  JPanel( new  FlowLayout());
    JPanel panel2 =  new  JPanel( new  FlowLayout());

     public   static   void  main(String[] args){
         new  Main();
    }

     public  Main() {
         this .setTitle("MinorAmp");
         this .setSize( 300 ,  400 );
         this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        main =  this ;
        addComponents();
         this .setVisible(true);
    }

     public   void  startPlay(){
        player.realize();
    }
     public   void  addComponents() {
        Container cp =  this .getContentPane();
        cp.setLayout( new  FlowLayout());
        cp.add(panel);
        cp.add(panel2);
        JButton button =  new  JButton("Start");
        button.addActionListener( new  ActionListener() {
             public   void  actionPerformed(ActionEvent ae) {
                JFileChooser chooser =  new  JFileChooser();
                chooser.showOpenDialog(panel);
                MediaLocator mrl =  null ;
                URL url =  null ;
                String mediaFile = "file://"+chooser.getSelectedFile().getAbsolutePath();
                 try  {
                    url =  new  URL(mediaFile);
                    mediaFile = url.toExternalForm();
                }  catch  (MalformedURLException mue) {
                    System.out.println(mue.toString());
                }
                System.out.println(url);
                 try  {
                    // Create a media locator from the file name
                     if  ((mrl =  new  MediaLocator(mediaFile)) ==  null ) Fatal("Can't build URL for " + mediaFile);
                    try {
                        player = Manager.createPlayer(mrl);
                    } catch (NoPlayerException e) {
                        System.out.println(e);
                        Fatal("Could not create player for " + mrl);
                    }

                    // Add ourselves as a listener for a player's events
                    player.addControllerListener(main);

                } catch (MalformedURLException e) {
                    Fatal("Invalid media file URL!");
                } catch (IOException e) {
                    Fatal("IO exception creating player  for  " + mrl);
                }
                startPlay();
            }

        });
        panel2.add(button);
    }

    public void controllerUpdate(ControllerEvent event) {
        // If we're getting messages from a dead player,
        // just leave
        if (player == null)
            return;

        // When the player is Realized, get the visual
        // and control components and add them to the Applet
        if (event instanceof RealizeCompleteEvent) {
            if (progressBar != null) {
                panel.remove(progressBar);
                progressBar = null;
            }

            int width = 320;
            int height = 0;
            if (controlComponent == null) {
                if ((controlComponent = player.getControlPanelComponent()) != null) {
                    controlPanelHeight = controlComponent.getPreferredSize().height;
                    panel.add(controlComponent);
                    height += controlPanelHeight;
                }
            }
            if (visualComponent == null) {
                if ((visualComponent = player.getVisualComponent()) != null) {
                    panel.add(visualComponent);
                    Dimension videoSize = visualComponent.getPreferredSize();
                    videoWidth = videoSize.width;
                    videoHeight = videoSize.height;
                    width = videoWidth;
                    height += videoHeight;
                    visualComponent.setBounds(0, 0, videoWidth, videoHeight);
                }
            }
            panel.setBounds(0, 0, width, height);
            if (controlComponent != null) {
                controlComponent.setBounds(0, videoHeight, width, controlPanelHeight);
                controlComponent.invalidate();
            }

        } else if (event instanceof CachingControlEvent) {
            if (player.getState() > Controller.Realizing)
                return;
            // Put a progress bar up when downloading starts,
            // take it down when downloading ends.
            CachingControlEvent e = (CachingControlEvent) event;
            CachingControl cc = e.getCachingControl();

            // Add the bar if not already there ...
            if (progressBar == null) {
                if ((progressBar = cc.getControlComponent()) != null) {
                    panel.add(progressBar);
                    panel.setSize(progressBar.getPreferredSize());
                    validate();
                }
            }
        } else if (event instanceof EndOfMediaEvent) {
            // We've reached the end of the media; rewind and
            // start over
            player.setMediaTime(new Time(0));
            player.start();
        } else if (event instanceof ControllerErrorEvent) {
            // Tell TypicalPlayerApplet.start() to call it a day
            player = null;
            Fatal(((ControllerErrorEvent) event).getMessage());
        } else if (event instanceof ControllerClosedEvent) {
            panel.removeAll();
        }

    }

    void Fatal(String s) {
        // Applications will make various choices about what
        // to do here. We print a message
        System.err.println("FATAL ERROR: " + s);
         throw   new  Error(s); // Invoke the uncaught exception
        // handler System.exit() is another
        // choice.

    }
}

Взято с сайта java.

выдаёт при загрузке mp3
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
file://D:/Musik/01.mp3
Error: Unable to realize com.sun.media.amovie.AMController@10efd7c
FATAL ERROR: Failed to realize
Exception in thread "JMF thread: SendEventQueue: com.sun.media.content.audio.mpeg.Handler" java.lang.Error: Failed to realize
	at com.minor.projects.mediaplayer.mpv01.Main.Fatal(Main.java: 169 )
	at com.minor.projects.mediaplayer.mpv01.Main.controllerUpdate(Main.java: 158 )
	at com.sun.media.BasicController.dispatchEvent(BasicController.java: 1254 )
	at com.sun.media.SendEventQueue.processEvent(BasicController.java: 1286 )
	at com.sun.media.util.ThreadedEventQueue.dispatchEvents(ThreadedEventQueue.java: 65 )
	at com.sun.media.util.ThreadedEventQueue.run(ThreadedEventQueue.java: 92 )
Error value: 800c000d
Я просто никогда не работал JMF седни токо начал.
Надо срочно, выручайте.
...
Рейтинг: 0 / 0
JMF MP3
    #33155580
Dima Yermak
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ну хот шо нибудь.
Хотя бы в какую сторону мне двигать?


Posted via ActualForum NNTP Server 1.2
...
Рейтинг: 0 / 0
JMF MP3
    #33155587
Фотография XM
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Dima Yermak wrote:
>
> Ну хот шо нибудь.
> Хотя бы в какую сторону мне двигать?
>
Здесь был?
http://java.sun.com/products/java-media/jmf/mp3/download.html
Posted via ActualForum NNTP Server 1.2
...
Рейтинг: 0 / 0
JMF MP3
    #33155629
Dima Yermak
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Был я там. Токо вот куда мои глаза глядели непонятно. :-)

Спасибо. Вопрос снят.

For the plugin to work within a JMF application, you need to :

- ensure that jmf.jar is also in the /lib/ext directory
- run the following command:


java com.sun.media.codec.audio.mp3.JavaDecoder


Posted via ActualForum NNTP Server 1.2
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / JMF MP3
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]