void CplayerDlg::PlayerOpenFile(void) { CFileDialog dlg(TRUE); TCHAR path[MAX_PATH]; char str [MAX_PATH]; // kill player progress timer KillTimer(TIMER_ID_PROGRESS); // stop player first if (g_hplayer) { player_close(g_hplayer); g_hplayer = NULL; } // open file dialog if (dlg.DoModal() == IDOK) { wcscpy_s(path, dlg.GetPathName()); WideCharToMultiByte(CP_ACP, 0, path, -1, str, MAX_PATH, NULL, NULL); } else { OnOK(); return; } // player open file g_hplayer = player_open(str, GetSafeHwnd()); if (g_hplayer) { m_bPlayPause = FALSE; /* int speed = 150; player_setparam(g_hplayer, PARAM_PLAYER_SPEED, &speed); */ // software volume scale -30dB to 12dB // range for volume is [-182, 73] // -255 - mute, +255 - max volume, 0 - 0dB int volume = -0; player_setparam(g_hplayer, PARAM_AUDIO_VOLUME, &volume); player_setrect(g_hplayer, 0, 0, 0, m_rtClient.right, m_rtClient.bottom - 2); player_setrect(g_hplayer, 1, 0, 0, m_rtClient.right, m_rtClient.bottom - 2); player_play(g_hplayer); SetTimer(TIMER_ID_PROGRESS, 100, NULL); } }
/* * Class: com_rockcarry_ffplayer_MediaPlayer * Method: nativeOpen * Signature: (Ljava/lang/String;Ljava/lang/Object;IILjava/lang/String;)J */ static jlong JNICALL nativeOpen(JNIEnv *env, jobject obj, jstring url, jobject jsurface, jint w, jint h, jstring params) { DO_USE_VAR(obj); DO_USE_VAR(jsurface); DO_USE_VAR(w); DO_USE_VAR(h); PLAYER_INIT_PARAMS playerparams; memset(&playerparams, 0, sizeof(playerparams)); if (params != NULL) { char *strparams = (char*)env->GetStringUTFChars(params, NULL); player_load_params(&playerparams, strparams); env->ReleaseStringUTFChars(params, strparams); } const char *strurl = env->GetStringUTFChars(url, NULL); playerparams.vdev_render_type = VDEV_RENDER_TYPE_ANDROID; jlong hplayer = (jlong)player_open((char*)strurl, obj, &playerparams); env->ReleaseStringUTFChars(url, strurl); return hplayer; }
int main(int argc, char *argv[]) { int k; struct coord c; unsigned int i; unsigned char turn_taken = 1, running = 0; seed_rng(); display_init(); if(player_init() == -1) return 0; level_init(&levels[0], 8); player_set_level(&levels[0]); while(1) { main_clear(); player_see(); player_status(); turn_taken = 0; if(!running) k = display_getch(); msg_clear(); switch(k) { case '8': case '9': case '6': case '3': case '2': case '1': case '4': case '7': case KEY_UP: case KEY_DOWN: case KEY_LEFT: case KEY_RIGHT: c = key_to_direction(k); if(!player_move(c.x, c.y)) running = 0; turn_taken = 1; break; case 'c': c = key_to_direction(ask_key("In which direction?")); msg_clear(); player_close(c.x, c.y); turn_taken = 1; break; case 'o': c = key_to_direction(ask_key("In which direction?")); msg_clear(); player_open(c.x, c.y); turn_taken = 1; break; case 'k': c = key_to_direction(ask_key("In which direction?")); msg_clear(); player_kick(c.x, c.y); turn_taken = 1; break; case 'g': case 'G': k = ask_key("In which direction?"); c = key_to_direction(k); if((c.x || c.y) && player_move(c.x, c.y)) running = 1; turn_taken = 1; break; case ':': player_look(); break; case ';': msg_printf("Pick an object..."); c = player_select_square(); msg_clear(); player_remote_look(c.x, c.y); break; case '.': turn_taken = 1; break; } if(turn_taken) { if(player_poll()) running = 0; for(i = 0; i < levels[0].nmonst; i++) if(monster_poll(levels[0].monsters[i])) running = 0; } } return 0; }
int main(int argc, char *argv[]) { if(argc != 2){ printf("Wring number of argv for player!\n"); return EXIT_FAILURE; } int id = atoi(argv[1]); if(id < 0){ printf("The id of player is negative\n"); return EXIT_FAILURE; } player_fifo* PlayerFifo=player_fifo_initial0(id); PlayerFifo->master_to_fd=open(PlayerFifo->master_to,O_WRONLY); PlayerFifo->master_from_fd=open(PlayerFifo->master_from,O_RDONLY); int n_p=0; char* out_message=malloc(BUFF_LEN*sizeof(*out_message)); fd_set rset; assert(read(PlayerFifo->master_from_fd,&n_p,sizeof(n_p))!=-1); if(n_p==-1){ free(out_message); close(PlayerFifo->master_to_fd); close(PlayerFifo->master_from_fd); player_fifo_free(PlayerFifo); return EXIT_FAILURE; } printf("Connected as player %d out of %d total palyers\n",id,n_p); player_fifo_initial1(PlayerFifo,id,n_p); player_open(id,n_p,PlayerFifo); clear_string(out_message); sprintf(out_message,"Player %d is ready to play",id); assert(write(PlayerFifo->master_to_fd,out_message,BUFF_LEN)!=-1); srand((unsigned)time(NULL)+id*10); unsigned int ran=rand()%2; POTATO_T item; memset(&item,0,sizeof(item)); while(1){ FD_ZERO(&rset); FD_SET(PlayerFifo->player_from_before_fd,&rset); FD_SET(PlayerFifo->master_from_fd,&rset); FD_SET(PlayerFifo->player_from_fd,&rset); int nfds=(PlayerFifo->player_from_before_fd>PlayerFifo->master_from_fd)?PlayerFifo->player_from_before_fd:PlayerFifo->master_from_fd; nfds=((nfds>PlayerFifo->player_from_fd)?nfds:PlayerFifo->player_from_fd); assert(select(nfds+1,&rset,NULL,NULL,NULL)>0); if(FD_ISSET(PlayerFifo->master_from_fd,&rset)){ assert(read(PlayerFifo->master_from_fd,&item,sizeof(item))!=-1); if(item.hop_count==1){ if(item.total_hops==1){ printf("I'm it\n"); item.hop_trace[item.total_hops-item.hop_count]=id; assert(write(PlayerFifo->master_to_fd,&item,sizeof(item))!=-1); } else if(item.total_hops==-1) break; } else{ item.hop_trace[item.total_hops-item.hop_count]=id; item.hop_count--; ran=rand()%2; if(ran==1){ assert(write(PlayerFifo->player_to_fd,&item,sizeof(item))!=-1); printf("Sending potato to %d\n",(id+1)%n_p); } else if(ran==0){ assert(write(PlayerFifo->player_to_before_fd,&item,sizeof(item))!=-1); printf("Sending potato to %d\n",((id==0)?(n_p-1):(id-1)%n_p) ); } } } else if(FD_ISSET(PlayerFifo->player_from_before_fd,&rset)){ assert(read(PlayerFifo->player_from_before_fd,&item,sizeof(item))!=-1); if(item.hop_count==1){ printf("I'm it\n"); item.hop_trace[item.total_hops-item.hop_count]=id; assert(write(PlayerFifo->master_to_fd,&item,sizeof(item))!=-1); } else{ item.hop_trace[item.total_hops-item.hop_count]=id; item.hop_count--; ran=rand()%2; if(ran==1){ assert(write(PlayerFifo->player_to_fd,&item,sizeof(item))!=-1); printf("Sending potato to %d\n",(id+1)%n_p); } else if(ran==0){ assert(write(PlayerFifo->player_to_before_fd,&item,sizeof(item))!=-1); printf("Sending potato to %d\n",((id==0)?(n_p-1):(id-1)%n_p) ); } } } else if(FD_ISSET(PlayerFifo->player_from_fd,&rset)){ assert(read(PlayerFifo->player_from_fd,&item,sizeof(item))!=-1); if(item.hop_count==1){ printf("I'm it\n"); item.hop_trace[item.total_hops-item.hop_count]=id; assert(write(PlayerFifo->master_to_fd,&item,sizeof(item))!=-1); } else{ item.hop_trace[item.total_hops-item.hop_count]=id; item.hop_count--; ran=rand()%2; if(ran==1){ assert(write(PlayerFifo->player_to_fd,&item,sizeof(item))!=-1); printf("Sending potato to %d\n",(id+1)%n_p); } else if(ran==0){ assert(write(PlayerFifo->player_to_before_fd,&item,sizeof(item))!=-1); printf("Sending potato to %d\n",((id==0)?(n_p-1):(id-1)%n_p) ); } } } } clear_string(out_message); sprintf(out_message,"Player %d is ready to exit",id); assert(write(PlayerFifo->master_to_fd,out_message,BUFF_LEN)!=-1); sleep(1); free(out_message); close(PlayerFifo->master_to_fd); close(PlayerFifo->master_from_fd); close(PlayerFifo->player_to_fd); close(PlayerFifo->player_from_fd); close(PlayerFifo->player_to_before_fd); close(PlayerFifo->player_from_before_fd); player_fifo_free(PlayerFifo); return EXIT_SUCCESS; }
EXPORT TIMESTAMP sync_player(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass) { struct player *my = OBJECTDATA(obj,struct player); TIMESTAMP t1 = (TS_OPEN == my->status) ? my->next.ts : TS_NEVER; TIMESTAMP temp_t; if (my->status==TS_INIT){ /* get local target if remote is not used and "value" is defined by the user at runtime */ if (my->target==NULL && obj->parent == NULL) my->target = gl_get_property(obj,"value",NULL); if(player_open(obj) == 0) { gl_error("sync_player: Unable to open player file '%s' for object '%s'", my->file, obj->name?obj->name:"(anon)"); } else { t1 = player_read(obj); } } while (my->status==TS_OPEN && t1<=t0 && my->next.ns==0 ) /* only use this method when not operating in subsecond mode */ { /* post this value */ if (my->target==NULL) my->target = gl_get_property(obj->parent,my->property,NULL); if (my->target==NULL){ gl_error("sync_player: Unable to find property \"%s\" in object %s", my->property, obj->name?obj->name:"(anon)"); my->status = TS_ERROR; } if (my->target!=NULL) { OBJECT *target = obj->parent ? obj->parent : obj; /* target myself if no parent */ gl_set_value(target,GETADDR(target,my->target),my->next.value,my->target); /* pointer => int64 */ } /* Copy the current value into our "tracking" variable */ my->delta_track.ns = my->next.ns; my->delta_track.ts = my->next.ts; memcpy(my->delta_track.value,my->next.value,sizeof(char256)); t1 = player_read(obj); } /* Apply an intermediate value, if necessary - mainly for "DELTA players in non-delta situations" */ if ((my->target!=NULL) && (my->delta_track.ts<t0) && (my->delta_track.ns!=0)) { OBJECT *target = obj->parent ? obj->parent : obj; /* target myself if no parent */ gl_set_value(target,GETADDR(target,my->target),my->delta_track.value,my->target); /* pointer => int64 */ } /* Delta-mode catch - if we're not explicitly in delta mode and a nano-second values pops up, try to advance past it */ if (((obj->flags & OF_DELTAMODE)!=OF_DELTAMODE) && (my->next.ns != 0) && (my->status==TS_OPEN)) { /* Initial value for next time */ temp_t = t1; /* Copied verbatim from above - just in case it still needs to be done - if a first timestep is a deltamode timestep */ if (my->target==NULL) my->target = gl_get_property(obj->parent,my->property,NULL); if (my->target==NULL){ gl_error("sync_player: Unable to find property \"%s\" in object %s", my->property, obj->name?obj->name:"(anon)"); my->status = TS_ERROR; } /* Advance to a zero */ while ((my->next.ns != 0) && (my->next.ts<=t0)) { /* Post the value as we go, so the "final" is correct */ /* Apply the "current value", if it is relevant (player_next_value contains the previous, so this will override it) */ if ((my->target!=NULL) && (my->next.ts<t0)) { OBJECT *target = obj->parent ? obj->parent : obj; /* target myself if no parent */ gl_set_value(target,GETADDR(target,my->target),my->next.value,my->target); /* pointer => int64 */ } /* Copy the value into the tracking variable */ my->delta_track.ns = my->next.ns; my->delta_track.ts = my->next.ts; memcpy(my->delta_track.value,my->next.value,sizeof(char256)); /* Perform the update */ temp_t = player_read(obj); } /* Apply the update */ t1 = temp_t; } else if (((obj->flags & OF_DELTAMODE)==OF_DELTAMODE) && (delta_mode_needed<t0)) /* Code to catch when gets stuck in deltamode (exits early) */ { if (my->next.ts<t0) { /* Advance to a value bigger than t0 */ while ((my->next.ns != 0) && (my->next.ts<=t0)) { /* Post the value as we go, so the "final" is correct */ /* Apply the "current value", if it is relevant (player_next_value contains the previous, so this will override it) */ if ((my->target!=NULL) && (my->next.ts<t0)) { OBJECT *target = obj->parent ? obj->parent : obj; /* target myself if no parent */ gl_set_value(target,GETADDR(target,my->target),my->next.value,my->target); /* pointer => int64 */ } /* Copy the value into the tracking variable */ my->delta_track.ns = my->next.ns; my->delta_track.ts = my->next.ts; memcpy(my->delta_track.value,my->next.value,sizeof(char256)); /* Perform the update */ temp_t = player_read(obj); } /* Do the adjustment of return */ if (t1 < t0) /* Sometimes gets stuck */ { /* Force it forward */ t1 = temp_t; } else /* Equal or greater than next time */ { if ((temp_t<t1) && (temp_t>t0)) t1 = temp_t; } } else if (my->next.ts == t0) { /* Roll it once */ /* Copy the value into the tracking variable */ my->delta_track.ns = my->next.ns; my->delta_track.ts = my->next.ts; memcpy(my->delta_track.value,my->next.value,sizeof(char256)); /* Perform the update */ temp_t = player_read(obj); } } /* See if we need to push a sooner update (DELTA round)*/ if ((my->delta_track.ts!=TS_NEVER) && (my->delta_track.ns != 0)) { /* Round the timestep up */ temp_t = my->delta_track.ts+1; /* Make sure it is still valid - don't want to get stuck iterating */ if ((temp_t<t1) && (temp_t>t0)) t1 = temp_t; } /* Catch for next delta instances that may occur -- if doesn't pass a reiteration, gets missed when nothing driving*/ if ((obj->flags & OF_DELTAMODE) == OF_DELTAMODE) { if ((t1>t0) && (my->next.ts==t0) && (my->next.ns != 0)) { /* Return us here, deltamode should have been flagged */ t1 = t0; } /* Check for a final stoppping point -- if player value goes ns beyond current stop time, it will get stuck and iterate */ if ((my->next.ts == gl_globalstoptime) && (my->next.ns != 0) && (t1 == gl_globalstoptime)) { /* Push it one second forward, just so GLD thinks it's done and can get out */ t1 = t1 + 1; } } obj->clock = t0; return t1; }