001/*******************************************************************************
002 * Copyright (c) 2024, 2026, Olivier Ayache.  All rights reserved.
003 *
004 * This file is part of AVPKit.
005 *
006 * AVPKit is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Lesser General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * AVPKit is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with AVPKit.  If not, see <http://www.gnu.org/licenses/>.
018 *******************************************************************************/
019
020package com.avpkit.mediatool.demos;
021
022import com.avpkit.mediatool.IMediaReader;
023import com.avpkit.mediatool.MediaListenerAdapter;
024import com.avpkit.mediatool.ToolFactory;
025
026/**
027 * Using {@link IMediaReader}, takes a media container, finds the first video stream,
028 * decodes that stream, and then plays the audio and video.
029 *
030 * @author aclarke
031 * @author trebor
032 */
033
034public class DecodeAndPlayAudioAndVideo extends MediaListenerAdapter
035{
036  /**
037   * Takes a media container (file) as the first argument, opens it,
038   * plays audio as quickly as it can, and opens up a Swing window and
039   * displays video frames with <i>roughly</i> the right timing.
040   *  
041   * @param args Must contain one string which represents a filename
042   */
043
044  public static void main(String[] args)
045  {
046    if (args.length <= 0)
047      throw new IllegalArgumentException(
048        "must pass in a filename as the first argument");
049    
050    // create a new mr. decode an play audio and video
051    IMediaReader reader = ToolFactory.makeReader(args[0]);
052    reader.addListener(ToolFactory.makeViewer());
053    while(reader.readPacket() == null)
054      do {} while(false);
055    
056  }
057
058}