static PyObject*
movie_stop (PyObject* self)
{
    SMPEG* movie = PyMovie_AsSMPEG (self);

    if (!SDL_WasInit (SDL_INIT_VIDEO))
        return RAISE (PyExc_SDLError,
                      "cannot convert without pygame.display initialized");

    Py_BEGIN_ALLOW_THREADS;
    SMPEG_stop (movie);
    Py_END_ALLOW_THREADS;
    Py_RETURN_NONE;
}
Exemple #2
0
PyObject *
_wrap_smpeg_stop (PyObject *self, PyObject *args)
{
	   PyObject *py_s;
	   
	   if (!PyArg_ParseTuple (args, "O:stop", &py_s)) return NULL;
	   GLASSERT (py_s && py_s != Py_None);

	   SMPEG *smpeg = AS_PTR(SMPEG, py_s);
	   GLASSERT (smpeg);

	   SMPEG_stop (smpeg);

	   RETURN_NONE;
}
int ONScripter::playMPEG(const char *filename, bool click_flag, bool loop_flag)
{
    unsigned long length = script_h.cBR->getFileLength( filename );
    if (length == 0){
        fprintf( stderr, " *** can't find file [%s] ***\n", filename );
        return 0;
    }

#ifdef ANDROID
    playVideoAndroid(filename);
    return 0;
#endif

    int ret = 0;
#if !defined(MP3_MAD) && !defined(USE_SDL_RENDERER)
    unsigned char *mpeg_buffer = new unsigned char[length];
    script_h.cBR->getFile( filename, mpeg_buffer );
    SMPEG *mpeg_sample = SMPEG_new_rwops( SDL_RWFromMem( mpeg_buffer, length ), NULL, 0 );

    if ( !SMPEG_error( mpeg_sample ) ){
        SMPEG_enableaudio( mpeg_sample, 0 );

        if ( audio_open_flag ){
            SMPEG_actualSpec( mpeg_sample, &audio_format );
            SMPEG_enableaudio( mpeg_sample, 1 );
        }
        SMPEG_enablevideo( mpeg_sample, 1 );
        SMPEG_setdisplay( mpeg_sample, screen_surface, NULL, NULL );
        SMPEG_setvolume( mpeg_sample, music_volume );
        SMPEG_loop(mpeg_sample, loop_flag);

        Mix_HookMusic( mp3callback, mpeg_sample );
        SMPEG_play( mpeg_sample );

        bool done_flag = false;
        while( !(done_flag & click_flag) && SMPEG_status(mpeg_sample) == SMPEG_PLAYING ){
            SDL_Event event;

            while( SDL_PollEvent( &event ) ){
                switch (event.type){
                  case SDL_KEYUP:
                    if ( ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_RETURN ||
                         ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_SPACE ||
                         ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_ESCAPE )
                        done_flag = true;
                    break;
                  case SDL_QUIT:
                    ret = 1;
                  case SDL_MOUSEBUTTONUP:
                    done_flag = true;
                    break;
                  default:
                    break;
                }
            }
            SDL_Delay( 10 );
        }

        SMPEG_stop( mpeg_sample );
        Mix_HookMusic( NULL, NULL );
        SMPEG_delete( mpeg_sample );

    }
    delete[] mpeg_buffer;
#else
    fprintf( stderr, "mpegplay command is disabled.\n" );
#endif

    return ret;
}
Exemple #4
0
void playVideo(const string &file) {

	//myFillRect(screen, NULL, 0);
	//SDL_GL_SwapBuffers();
	
    SMPEG *mpeg;
	SMPEG_Info info;
	mpeg = SMPEG_new(file.c_str(), &info, false);
	bool hasAudio = (info.has_audio > 0);
	
	if ( SMPEG_error(mpeg) ) {
		dout << "MPEG error: "  << SMPEG_error(mpeg) << endl;
		exit(1);
	}
	
	int done = 0;

    SDL_Surface *videoSurface = SDL_AllocSurface( SDL_SWSURFACE,
				nearestPow2(info.width),
				nearestPow2(info.height),
				32,
				0x000000FF,
				0x0000FF00,
				0x00FF0000,
				0xFF000000 );

	if ( !videoSurface ) {
		dout << "Failed to allocate memory for video playback" << endl;
		exit(1);
	}

	
	SMPEG_enablevideo(mpeg, 1);

	SDL_mutex *mutex = SDL_CreateMutex();

	SMPEG_setdisplay(mpeg, videoSurface, mutex, videoUpdate );

	SMPEG_scaleXY(mpeg, info.width, info.height);

	//SMPEG_setdisplayregion(mpeg, 0, 0, info.width, info.height);

	//SMPEG_setdisplay(mpeg, screen, NULL, update);

	
	if(hasAudio) {
		SDL_AudioSpec audiofmt;
		Uint16 format;
		int freq, channels;
		
		/* Tell SMPEG what the audio format is */
		Mix_QuerySpec(&freq, &format, &channels);
		audiofmt.format = format;
		audiofmt.freq = freq;
		audiofmt.channels = channels;
		SMPEG_actualSpec(mpeg, &audiofmt);
		
		/* Hook in the MPEG music mixer */
		Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
		SMPEG_enableaudio(mpeg, 1);
		SMPEG_setvolume(mpeg, 100);
	} else {
		Mix_PauseMusic();
		SMPEG_enableaudio(mpeg, 0);
	}
	
	glBlendFunc(GL_ONE, GL_ZERO);
	glEnable(GL_TEXTURE_2D);
	
	SMPEG_play(mpeg);

    while( !done && SMPEG_status( mpeg ) == SMPEG_PLAYING ) {
        SDL_Event event;

        while ( SDL_PollEvent(&event) ) {
			switch (event.type) {
				case SDL_KEYDOWN:
				{
					if ( event.key.keysym.sym == SDLK_SPACE ) {
						done = 1;
					}
	                break;
				}

				case SDL_QUIT:
				{
					exit(1);
				}

				default:
					break;
            }
        }

		if(drawVideoFrame) {
			SDL_mutexP(mutex);
			drawVideoFrame = false;
			drawVideo(videoSurface, info.width, info.height);
			//printf("draw in %i\n", time(NULL));
			SDL_mutexV(mutex);
		    SDL_GL_SwapBuffers();
		}

    }

	SMPEG_stop(mpeg);

	if(hasAudio) {
		Mix_HookMusic(NULL, NULL);
	} else {
		Mix_ResumeMusic();
	}

	SDL_FreeSurface(videoSurface);

	myFillRect(screen, NULL, 0);
    SDL_GL_SwapBuffers();
	
	SMPEG_delete(mpeg);
}
// Stops the movie, but keeps current position
void CSmpeg::Stop()
{
	SMPEG_stop( movie );
	if(SMPEG_error(movie) != NULL)
	log << WARN << "Stop() error: " << SMPEG_error(movie) << endl;
}