vlcj로 youtube 비디오를 재생하는 데 문제가 있습니다. 지난 주까지 모든 일이 진행되고있었습니다. 나는 mediaPlayer.playMedia ("http://www.youtube.com/watch?v=1t8fl96HPQI")를 호출하고 있었지만 정상적으로 작동했지만 더 이상 작동하지 않았습니다. 그것은 전혀 오류를 발생시키지 않습니다. 로컬 파일 및 기타 온라인 스트리밍 URL은 재생할 수 있지만 YouTube 동영상은 재생할 수 없습니다.vlcj가 더 이상 작동하지 않는 youtube 비디오 재생
이것은 내가 사용하고있는 코드입니다.
mediaPlayer.setPlaySubItems(true); // <--- This is very important for YouTube media
아래 코드는 모든 하위 항목을 가져옵니다 YouTube 동영상의 경우 (기본적으로 자사의 준비 예)
/*
* This file is part of VLCJ.
*
* VLCJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VLCJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VLCJ. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2009, 2010, 2011 Caprica Software Limited.
*/
package com.javacodegeeks.youtube.test;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.EmptyBorder;
import uk.co.caprica.vlcj.binding.internal.libvlc_media_t;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.test.VlcjTest;
/**
* A minimal YouTube player.
* <p>
* The URL/MRL must be in the following format:
* <pre>
* http://www.youtube.com/watch?v=000000
* </pre>
* The only thing that makes this different from a 'regular' media player
* application is the following piece of code:
* <pre>
* mediaPlayer.setPlaySubItems(true); // <--- This is very important for YouTube media
* </pre>
* Note that it is also possible to programmatically play the sub-item in
* response to events - this is slightly more complex but more flexible.
* <p>
* The YouTube web page format changes from time to time. This means that the
* lua scripts that vlc provides to parse the YouTube web pages when looking
* for the media to stream may not work. If you get errors, especially errors
* alluding to malformed urls, then you may need to update your vlc version to
* get newer lua scripts.
*/
public class NewClass extends VlcjTest {
private MediaPlayerFactory factory;
private EmbeddedMediaPlayer mediaPlayer;
private Frame mainFrame;
private JLabel urlLabel;
private JTextField urlTextField;
private JButton playButton;
public static void main(String[] args) throws Exception {
setLookAndFeel();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new NewClass().start();
}
});
}
public NewClass() {
mainFrame = new Frame("vlcj YouTube Test");
mainFrame.setIconImage(new ImageIcon(getClass().getResource("/icons/vlcj-logo.png")).getImage());
mainFrame.setSize(800, 600);
mainFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
exit(0);
}
});
mainFrame.setLayout(new BorderLayout());
JPanel cp = new JPanel();
cp.setBackground(Color.black);
cp.setLayout(new BorderLayout());
JPanel ip = new JPanel();
ip.setBorder(new EmptyBorder(4, 4, 4, 4));
ip.setLayout(new BoxLayout(ip, BoxLayout.X_AXIS));
urlLabel = new JLabel("URL:");
urlLabel.setDisplayedMnemonic('u');
urlLabel.setToolTipText("Enter a URL in the format http://www.youtube.com/watch?v=000000");
urlTextField = new JTextField(40);
urlTextField.setFocusAccelerator('u');
urlTextField.setToolTipText("Enter a URL in the format http://www.youtube.com/watch?v=000000");
playButton = new JButton("Play");
playButton.setMnemonic('p');
ip.add(urlLabel);
ip.add(urlTextField);
ip.add(playButton);
cp.add(ip, BorderLayout.NORTH);
Canvas vs = new Canvas();
vs.setBackground(Color.black);
cp.add(vs, BorderLayout.CENTER);
mainFrame.add(cp, BorderLayout.CENTER);
urlTextField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
play();
}
});
playButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
play();
}
});
factory = new MediaPlayerFactory();
mediaPlayer = factory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(factory.newVideoSurface(vs));
mediaPlayer.setPlaySubItems(true); // <--- This is very important for YouTube media
mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
@Override
public void mediaSubItemAdded(MediaPlayer mediaPlayer, libvlc_media_t subItem) {
List<String> items = mediaPlayer.subItems();
System.out.println(items);
System.out.println(mediaPlayer.subItemCount());
}
});
}
private void start() {
mainFrame.setVisible(true);
}
private void play() {
String mrl = urlTextField.getText();
mediaPlayer.playMedia(mrl);
}
private void exit(int value) {
mediaPlayer.stop();
mediaPlayer.release();
factory.release();
System.exit(value);
}
/**
* Set the cross platform look and feel.
*
* @throws Exception if an error occurs
*/
// private static void setLookAndFeel() throws Exception {
// String lookAndFeelClassName = null;
// LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();
// for(LookAndFeelInfo lookAndFeel : lookAndFeelInfos) {
// if("Nimbus".equals(lookAndFeel.getName())) {
// lookAndFeelClassName = lookAndFeel.getClassName();
// }
// }
// if(lookAndFeelClassName == null) {
// lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName();
// }
// UIManager.setLookAndFeel(lookAndFeelClassName);
// }
}
당신은이 코드를합니다. 이 일하는
mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
@Override
public void mediaSubItemAdded(MediaPlayer mediaPlayer, libvlc_media_t subItem) {
List<String> items = mediaPlayer.subItems();
System.out.println(items);
System.out.println(mediaPlayer.subItemCount());
}
});
, 난 위의 코드는이 개 하위 항목, 비디오의 실제 URL 인 중 하나를 인쇄하는 것으로 나타났습니다.
하지만 지금은 인쇄이 같은 하나 개의 하위 항목 :
[http://www.youtube.com/get_video_info?video_id=1t8fl96HPQI & 엘 = detailpage]의 실제 URL이 아닙니다
비디오와 나는 그것이 왜 놀지 않는지 생각한다.
왜 이런 일이 일어나는 지 알고 싶습니다. Google이 자신의 YouTube 페이지 형식으로 무엇인가를 변경 했습니까?
내가 찾은 튜토리얼에서 제안한 것처럼 vlc youtube.lua 파일을 업그레이드하려고했지만 운이 없었습니다.
또한 vlc에서 동일한 링크를 사용할 때 제대로 작동합니다.
사양 :
우분투 12.0.4 64 비트
VLC 미디어 플레이어 2.0.5 Twoflower
vlcj 미리 2.2.0
감사
마리오