1 /*****************************************************************************
2 * LibVlcMediaInstanceTest.java: VLC Java Bindings
3 *****************************************************************************
4 * Copyright (C) 1998-2008 the VideoLAN team
6 * Authors: Filippo Carone <filippo@carone.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 package org.videolan.jvlc.internal;
28 import org.junit.After;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
33 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
34 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
35 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
38 public class LibVlcMediaInstanceTest
41 private LibVlc libvlc = LibVlc.SYNC_INSTANCE;
43 private LibVlcInstance libvlcInstance;
45 private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
47 private libvlc_exception_t exception;
50 public void testSetup()
52 exception = new libvlc_exception_t();
53 libvlcInstance = libvlc.libvlc_new(0, new String[]{"-vvv","-I","dummy","-aout=dummy","-vout=dummy"}, exception);
54 libvlc.libvlc_exception_clear(exception);
58 public void tearDown()
60 libvlc.libvlc_release(libvlcInstance);
61 libvlc.libvlc_exception_clear(exception);
65 public void mediaInstanceNew()
67 LibVlcMediaInstance instance = libvlc.libvlc_media_instance_new(libvlcInstance, exception);
68 Assert.assertNotNull(instance);
69 Assert.assertEquals(0, exception.raised);
73 public void mediaInstancePlayBad()
75 LibVlcMediaInstance instance = libvlc.libvlc_media_instance_new(libvlcInstance, exception);
76 libvlc.libvlc_media_instance_play(instance, exception);
77 Assert.assertEquals(1, exception.raised); // no associated media descriptor
81 public void mediaInstancePlay()
83 LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
84 LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
85 libvlc.libvlc_media_instance_play(mi, exception);
86 Assert.assertEquals(0, exception.raised);
90 public void mediaInstancePauseBad()
92 LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
93 LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
94 libvlc.libvlc_media_instance_pause(mi, exception);
95 Assert.assertEquals(1, exception.raised);
99 public void mediaInstancePause()
101 LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
102 LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
103 libvlc.libvlc_media_instance_play(mi, exception);
104 libvlc.libvlc_media_instance_pause(mi, exception);
105 Assert.assertEquals(0, exception.raised);
109 public void mediaInstanceSetPosition()
111 LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
112 LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
113 libvlc.libvlc_media_instance_play(mi, exception);
114 libvlc.libvlc_media_instance_set_position(mi, 0.5f, exception);
115 Assert.assertEquals(0, exception.raised);
116 float position = libvlc.libvlc_media_instance_get_position(mi, exception);
117 Assert.assertTrue("Position is: " + position, position >= 0.5f);
121 public void mediaInstanceStop()
123 LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
124 LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
125 libvlc.libvlc_media_instance_stop(mi, exception);
126 Assert.assertEquals(0, exception.raised);
130 public void mediaInstanceStop2()
132 LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
133 LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
134 libvlc.libvlc_media_instance_play(mi, exception);
135 libvlc.libvlc_media_instance_stop(mi, exception);
136 Assert.assertEquals(0, exception.raised);