Commits

Anonymous committed f127db7

Made some small alterations, trying to fix audio and unpausing.

Comments (0)

Files changed (3)

-#! /usr/bin/env python
-print "importing time"
-import time
-print "time imported"
-print "importing pygame"
+import time 
 import pygame
-print "pygame imported"
-print "pygame.init()"
 pygame.init() #or we could just call pygame.display.init() as thats all we need
-print "pygame initialized"
-print "pygame.mixer.quit()"
 pygame.mixer.quit() #This needs to be done, as the default sound system of the 
                     # ffmpeg-wrapper uses SDL_mixer, and this would cause major
                     # conflicts with the mixer module.
-print "mixer quit"
-print "importing movie"
 import pygame.nmovie as movie
-print "movie imported"
+
 print "Please give an (absolute)filename of a movie file you'd like to play: ",
 #filename = raw_input()
-filename="/home/tyler/War3.avi"
+filename="/home/tyler/dhs1.avi"
 #initialization. It could also have a surface as a second argument, and every 
 # frame will be blitted to that surface. It is the programmer's responsibility
 # to be on time for rendering that surface.
 
 print m         #calls __repr__, which will show the filename, and the current 
                 # timestamp. 
+#print "repeated looping plays.."
+#m.play(10)
+#time.sleep(10*30)
+
+
+print "Playing infinitely"
 
 m.play(-1)      #We're going to use infinite play, so we can demonstrate all 
                 # the features.
 #Now we're going to play with the size of the window, affecting the video on 
 # the fly. resize(width, height) is the main function, changes them both at
 # the same time.
+print "Resizing..."
 m.resize(m.width/2, m.height*2)
+print "sleeping..."
 time.sleep(10) #another ten second nap.
-m.width = m.width*4 
+print "Resizing again..."
+m.width = m.width*4
+print "sleeping again" 
 time.sleep(10)
+print "Back to normal!"
 m.width=m.width/2
 m.height = m.height/2
+print "and again, sleeping..."
 #back to our original size
 time.sleep(10)
 #Here we demonstrate the use of pause. You pause, then call pause again to play
+print "Pausing..."
+m.pause()
+print "done pausing..."
+print m.paused
+print m.playing
+time.sleep(2)
+print "Unpausing..."
 m.pause()
 print m.paused
 print m.playing
-time.sleep(2)
-m.pause()
-print m.paused
-print m.playing
+time.sleep(20)
 #Here is the stop function. Right now, rewind is the exact same as stop.
+print "Stopping..."
 m.stop()
 time.sleep(3)
 #And now we restart playing.
+print "Playing again..."
 m.play(-1)
 
+time.sleep(10)
+print "Surface time..."
 screen = pygame.display.set_mode((m.width, m.height))
 #This will move the movie player from overlay mode to blitting to the surface 
 # we've given it. This means it is our responsibility to update the display on 
 # time.
 
 counter = 0
-actions = {5: lambda x: x.pause(), 10: lambda x: x.pause(), 15: lambda x: x.resize(x.width/2, x.height/2), 20:lambda x: x.stop(), 22: lambda x: x.play(-1)}
+actions = {1: lambda x: x.paused, 5: lambda x: x.pause(), 10: lambda x: x.pause(), 15: lambda x: x.resize(x.width/2, x.height/2), 20:lambda x: x.stop(), 22: lambda x: x.play(-1)}
 prev_time = time.time()
 m.surface = screen
+print "About to do surface gymnastics..."
 while(1):
     new_time=time.time()
     diff = int(new_time-prev_time)
     if(diff>=1):
         counter+=1
-    prev_time=new_time
+        print counter
+        prev_time=new_time
+    #print "testing counter"
     if counter==30:
+        #print "breaking"
         break
+    #print "has_key"
     if actions.has_key(counter):
+        print "Performing action at counter value: %d" % counter
         actions[counter](m)
-    pygame.display.update() #we can do this because we're blitting each frame of the movie to the main screen we instantiated.
+        counter +=1
+    #print "updating"
+    time.sleep(0.1) #we need to let go of the gil occassionally...
+    if(not screen.get_locked()):
+        pygame.display.update() #we can do this because we're blitting each frame of the movie to the main screen we instantiated.
     
+m.stop()
 del m
 #the end
 
 {
     AVPacketList *pkt1;
 
+	/* duplicate the packet */
+    if (pkt!=&flush_pkt && av_dup_packet(pkt) < 0)
+        return -1;
+
     pkt1 = PyMem_Malloc(sizeof(AVPacketList));
     
     if (!pkt1)
         return -1;
-    av_dup_packet(pkt);
     pkt1->pkt = *pkt;
     pkt1->next = NULL;
 
 	int h=0;
 	get_height_width(movie, &h, &w);
 	
-	if(!vp->dest_overlay||!vp->dest_surface||vp->width!=movie->width||vp->height!=movie->height)
+	if((!vp->dest_overlay && vp->overlay>0)||(!vp->dest_surface && vp->overlay<=0)||vp->width!=movie->width||vp->height!=movie->height)
 	{
 		video_open(movie, movie->pictq_windex);
 	}	
 /* pause or resume the video */
 void stream_pause(PyMovie *movie)
 {
-	/*DECLAREGIL
-	GRABGIL*/
     Py_INCREF( movie);
-    //RELEASEGIL
     int paused = movie->paused;
-    //SDL_LockMutex(movie->dest_mutex);
     movie->paused = !movie->paused;
     if (!movie->paused) 
     {
 		movie->frame_timer += (av_gettime() - movie->video_current_pts_time) / 1000000.0;
     }
     movie->last_paused=paused;
-    //SDL_UnlockMutex(movie->dest_mutex);
-    //GRABGIL
     Py_DECREF( movie);
-	//RELEASEGIL
 }
 
 
 	int co = 0;
 	for(;co<2;co++)
 	{
-		if(movie->audio_paused && !movie->paused)
+		if      (!movie->paused && movie->audio_paused)
 		{
 			pauseBuffer(movie->channel);
 			movie->audio_paused = 0;	
 		}
-		if (movie->paused && !movie->audio_paused) {
+		else if (movie->paused && !movie->audio_paused)  
+        {
         	pauseBuffer(movie->channel);
         	movie->audio_paused = 1;
             goto closing;
     do {
     	
         if (movie->paused && !movie->videoq.abort_request) {
-	    	goto the_end;
+	    	break;
 	    }
         if (packet_queue_get(&movie->videoq, pkt, 0) <=0)
             break;
 int soundQuit(void)
 {
 	queue_flush(&queue);
+	stopBuffer(s_channel);
+	Mix_ChannelFinished(NULL);
 	Mix_CloseAudio();
 	return 0;
 }