]> git.sesse.net Git - vlc/blob - mozilla/vlcplugin.cpp
75ba43b15a2737d9478d39af80a37a1e530008d2
[vlc] / mozilla / vlcplugin.cpp
1 /*****************************************************************************
2  * vlcplugin.cpp: a VideoLAN Client plugin for Mozilla
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: vlcplugin.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <npapi.h>
28
29 #include <vlc/vlc.h>
30
31 #include "vlcpeer.h"
32 #include "vlcplugin.h"
33
34 /*****************************************************************************
35  * VlcPlugin methods
36  *****************************************************************************/
37 VlcPlugin::VlcPlugin( NPP instance )
38 {
39     p_instance = instance; 
40     p_peer = NULL;
41 }
42
43
44 VlcPlugin::~VlcPlugin()
45 {
46     if( p_peer )
47     {
48         p_peer->Disable();
49         p_peer->Release();
50     }
51 }
52
53
54 void VlcPlugin::SetInstance( NPP instance )
55 {
56     p_instance = instance;
57 }
58
59
60 NPP VlcPlugin::GetInstance()
61 {
62     return p_instance;
63 }
64
65
66 void VlcPlugin::SetFileName(const char * filename)
67 {
68 fprintf(stderr, "VlcPlugin::SetFilename %s\n", filename);
69 #if 0
70     FILE * fh;
71     fh = fopen(filename, "rb");
72     if(!fh)
73     {
74         fprintf(stderr, "Error while opening %s.\n", filename);
75         return;
76     }
77     fseek(fh, 0, SEEK_END);
78     m_lSize = ftell(fh);
79     m_szSound = (char*) malloc(m_lSize);
80     if(!m_szSound)
81     {
82         fprintf(stderr, "Error while allocating memory.\n");
83         fclose(fh);
84         return;
85     }
86     rewind(fh);
87     long pos = 0;
88     do
89     {
90         pos += fread(m_szSound + pos, 1, m_lSize - pos, fh);
91         fprintf(stderr, "pos = %d\n", pos);
92     }
93     while (pos < m_lSize -1);
94     fclose (fh);
95     fprintf(stderr, "File loaded\n");
96 #endif
97     return; 
98 }
99
100 void VlcPlugin::Play()
101 {
102 fprintf(stderr, "VlcPlugin::Play\n");
103 }
104
105 void VlcPlugin::Pause()
106 {
107 fprintf(stderr, "VlcPlugin::Pause\n");
108 }
109
110 void VlcPlugin::Stop()
111 {
112 fprintf(stderr, "VlcPlugin::Stop\n");
113 }
114
115 VlcIntf* VlcPlugin::getScriptable()
116 {
117     if( !p_peer )
118     {
119         p_peer = new VlcPeer( this );
120         if( p_peer == NULL ) 
121         {
122             return NULL;
123         }
124         
125         NS_ADDREF( p_peer );
126     }
127     // a getter should addref for its caller.
128     NS_ADDREF( p_peer );
129     return p_peer;
130 }
131