private void applyResult(int resultCode) { vPlayerHandler.removeMessages(BUFFER_PROGRESS); Intent i = new Intent(); i.putExtra("filePath", mUri.toString()); if (isInitialized()) { i.putExtra("position", (double) vPlayer.getCurrentPosition() / vPlayer.getDuration()); i.putExtra("duration", vPlayer.getDuration()); savePosition(); } switch (resultCode) { case RESULT_FAILED: if (toast != null) { toast.setText(R.string.video_cannot_play); toast.setDuration(Toast.LENGTH_SHORT); toast.show(); } else { toast = Toast.makeText(this, R.string.video_cannot_play, Toast.LENGTH_SHORT); toast.show(); } break; case RESULT_CANCELED: case RESULT_OK: break; } setResult(resultCode, i); }
protected void startPlayer() { if (isInitialized() && mScreenReceiver.screenOn && !vPlayer.isBuffering()) { if (!vPlayer.isPlaying()) { vPlayer.start(); } } }
private void setVideoLayout() { mVideoView.setVideoLayout( mVideoMode, VP.DEFAULT_ASPECT_RATIO, vPlayer.getVideoWidth(), vPlayer.getVideoHeight(), vPlayer.getVideoAspectRatio()); }
private void release() { if (vPlayer != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { android.os.Process.killProcess(android.os.Process.myPid()); } else { vPlayer.release(); vPlayer.releaseContext(); } } }
@Override public void onPlaybackComplete() { mEnd = true; if (mLoopCount == 0 || mLoopCount-- > 1) { vPlayer.start(); vPlayer.seekTo(0); } else { resultFinish(RESULT_OK); } }
private void reOpen(Uri path, String name, boolean fromStart) { if (isInitialized()) { savePosition(); vPlayer.release(); vPlayer.releaseContext(); } Intent i = getIntent(); i.putExtra("lockScreen", mMediaController.isLocked()); i.putExtra("startPosition", lastposition); i.putExtra("fromStart", fromStart); i.putExtra("displayName", name); i.setData(path); parseIntent(i); mUri = path; if (mViewRoot != null) mViewRoot.invalidate(); mOpened.set(false); }
@Override public void onPause() { super.onPause(); if (!mCreated) return; if (isInitialized()) { savePosition(); if (vPlayer != null && vPlayer.isPlaying()) { stopPlayer(); } } }
@Override public void onStop() { super.onStop(); if (!mCreated) return; if (isInitialized()) { vPlayer.releaseSurface(); } if (mServiceConnected) { unbindService(vPlayerServiceConnection); mServiceConnected = false; } }
@Override public float scale(float scaleFactor) { float userRatio = VP.DEFAULT_ASPECT_RATIO; int videoWidth = vPlayer.getVideoWidth(); int videoHeight = vPlayer.getVideoHeight(); float videoRatio = vPlayer.getVideoAspectRatio(); float currentRatio = mVideoView.mVideoHeight / (float) videoHeight; currentRatio += (scaleFactor - 1); if (videoWidth * currentRatio >= VIDEO_MAXIMUM_WIDTH) currentRatio = VIDEO_MAXIMUM_WIDTH / (float) videoWidth; if (videoHeight * currentRatio >= VIDEO_MAXIMUM_HEIGHT) currentRatio = VIDEO_MAXIMUM_HEIGHT / (float) videoHeight; if (currentRatio < 0.5f) currentRatio = 0.5f; mVideoView.mVideoHeight = (int) (videoHeight * currentRatio); mVideoView.setVideoLayout(mVideoMode, userRatio, videoWidth, videoHeight, videoRatio); return currentRatio; }
@Override public void onDestroy() { super.onDestroy(); if (!mCreated) return; manageReceivers(); if (isInitialized() && !vPlayer.isPlaying()) release(); if (mMediaController != null) mMediaController.release(); try { android.os.Process.killProcess(android.os.Process.myPid()); } catch (Exception e) { } }
@Override public void onSurfaceDestroyed(SurfaceHolder holder) { if (vPlayer != null && vPlayer.isInitialized()) { if (vPlayer.isPlaying()) { vPlayer.stop(); vPlayer.setState(PlayerService.STATE_NEED_RESUME); } vPlayer.releaseSurface(); if (vPlayer.needResume()) vPlayer.start(); } }
public void run(ActorSystem newActorSystem) { Thread.currentThread().setName("game-machine"); if (!AppConfig.getOrm()) { throw new RuntimeException("Orm is now required"); } actorSystem = newActorSystem; actorSystem.actorOf( Props.create(EventStreamHandler.class), EventStreamHandler.class.getSimpleName()); actorSystem.actorOf( new RoundRobinPool(20).props(Props.create(RemoteEcho.class)), RemoteEcho.name); startCacheUpdateHandler(); ZoneService.init(); GameMessageRoute.add(ZoneService.name, ZoneService.name, false); ActorUtil.createActor(ZoneService.class, ZoneService.name); actorSystem.actorOf(Props.create(GameLimits.class), GameLimits.class.getSimpleName()); GameMessageRoute.add(AkkaProcessRunner.name, AkkaProcessRunner.name, false); ActorUtil.createActor(AkkaProcessRunner.class, AkkaProcessRunner.name); actorSystem.actorOf(Props.create(GridExpiration.class), GridExpiration.class.getSimpleName()); PlayerService.getInstance().createAgentControllers(); GridService.getInstance().createDefaultGrids(); RegionManager.start(); actorSystem.actorOf(Props.create(UnityGameMessageHandler.class), UnityGameMessageHandler.name); GameMessageRoute.add(UnityInstanceManager.name, UnityInstanceManager.name, false); ActorUtil.createActor(UnityInstanceManager.class, UnityInstanceManager.name); TestRunner.run(); Runtime.getRuntime() .addShutdownHook( new Thread() { public void run() { UnityProcessManager.stopAll(); getActorSystem().shutdown(); } }); }
private void loadVPlayerPrefs() { if (!isInitialized()) return; vPlayer.setBuffer(VP.DEFAULT_BUF_SIZE); vPlayer.setVideoQuality(VP.DEFAULT_VIDEO_QUALITY); vPlayer.setDeinterlace(VP.DEFAULT_DEINTERLACE); vPlayer.setVolume(VP.DEFAULT_STEREO_VOLUME, VP.DEFAULT_STEREO_VOLUME); vPlayer.setSubEncoding(VP.DEFAULT_SUB_ENCODING); MarginLayoutParams lp = (MarginLayoutParams) mSubtitleContainer.getLayoutParams(); lp.bottomMargin = (int) VP.DEFAULT_SUB_POS; mSubtitleContainer.setLayoutParams(lp); vPlayer.setSubShown(mSubShown); setTextViewStyle(mSubtitleText); if (!TextUtils.isEmpty(mSubPath)) vPlayer.setSubPath(mSubPath); if (mVideoView != null && isInitialized()) setVideoLayout(); }
/** * Removes from db characters that should be deleted (their deletion time has passed). * * @param account */ private static void removeDeletedCharacters(Account account) { /* Removes chars that should be removed */ Iterator<PlayerAccountData> it = account.iterator(); while (it.hasNext()) { PlayerAccountData pad = it.next(); Race race = pad.getPlayerCommonData().getRace(); long deletionTime = ((long) pad.getDeletionTimeInSeconds()) * 1000; if (deletionTime != 0 && deletionTime <= System.currentTimeMillis()) { it.remove(); account.decrementCountOf(race); PlayerService.deletePlayerFromDB(pad.getPlayerCommonData().getPlayerObjId()); if (GSConfig.FACTIONS_RATIO_LIMITED && pad.getPlayerCommonData().getLevel() >= GSConfig.FACTIONS_RATIO_LEVEL) { if (account.getNumberOf(race) == 0) { GameServer.updateRatio(pad.getPlayerCommonData().getRace(), -1); } } } } }
protected ModelAndView handleRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); // String id = request.getParameter("id"); // MediaFile mediaFile = mediaFileService.getMediaFile(path); int listOffset = DEFAULT_LIST_OFFSET; int listSize = DEFAULT_LIST_SIZE; String listType = DEFAULT_LIST_TYPE; User user = securityService.getCurrentUser(request); String username = user.getUsername(); UserSettings userSettings = settingsService.getUserSettings(username); int userGroupId = securityService.getCurrentUserGroupId(request); if (request.getParameter("listOffset") != null) { listOffset = Math.max( 0, Math.min(Integer.parseInt(request.getParameter("listOffset")), MAX_LIST_OFFSET)); } if (request.getParameter("listSize") != null) { listSize = Math.max(0, Math.min(Integer.parseInt(request.getParameter("listSize")), MAX_LIST_SIZE)); } if (request.getParameter("listType") != null) { listType = String.valueOf(request.getParameter("listType")); } List<MediaFile> songs; if ("topplayed".equals(listType)) { songs = mediaFileDao.getTopPlayedCountForUser(listOffset, listSize, username); } else if ("otheruser".equals(listType)) { songs = mediaFileDao.getLastPlayedCountForAllUser(listOffset, listSize, userGroupId); } else if ("overall".equals(listType)) { songs = mediaFileDao.getTopPlayedCountForAllUser(listOffset, listSize, userGroupId); } else if ("lastplayed".equals(listType)) { songs = mediaFileDao.getLastPlayedCountForUser(listOffset, listSize, username); } else { songs = mediaFileDao.getLastPlayedCountForAllUser(0, 1, userGroupId); } mediaFileService.populateStarredDate(songs, username); map.put("user", user); map.put("songs", songs); map.put("partyModeEnabled", userSettings.isPartyModeEnabled()); map.put("player", playerService.getPlayer(request, response)); map.put("listOffset", listOffset); map.put("listSize", listSize); map.put("listType", listType); // map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null); ModelAndView result = super.handleRequestInternal(request, response); result.addObject("model", map); return result; }
@Override public void Stop() throws RemoteException { // TODO Auto-generated method stub mPlayerService.Stop(); }
@Override public void setVideoQuality(int quality) { // TODO Auto-generated method stub if (isInitialized()) vPlayer.setVideoQuality(quality); }
private void savePosition() { if (vPlayer != null && mUri != null) { if (mEnd) lastposition = 1.0f; else lastposition = (float) (vPlayer.getCurrentPosition() / (double) vPlayer.getDuration()); } }
@Override public void onSurfaceCreated(SurfaceHolder holder) { mSurfaceCreated = true; if (mServiceConnected) vPlayerHandler.sendEmptyMessage(OPEN_FILE); if (vPlayer != null) vPlayer.setDisplay(holder); }
@Override public void seekTo(long arg0) { if (isInitialized()) vPlayer.seekTo((float) ((double) arg0 / vPlayer.getDuration())); }
@Override public void start() { if (isInitialized()) vPlayer.start(); }
@Override public boolean isPlaying() { if (isInitialized()) return vPlayer.isPlaying(); return false; }
@Override public void pause() { if (isInitialized()) vPlayer.stop(); }
@Override public long getDuration() { if (isInitialized()) return vPlayer.getDuration(); return 0; }
@Override public void handleMessage(Message msg) { switch (msg.what) { case OPEN_FILE: synchronized (mOpenLock) { if (!mOpened.get() && vPlayer != null) { mOpened.set(true); vPlayer.setVPlayerListener(vPlayerListener); if (vPlayer.isInitialized()) mUri = vPlayer.getUri(); if (mVideoView != null) vPlayer.setDisplay(mVideoView.getHolder()); if (mUri != null) vPlayer.initialize( mUri, mDisplayName, mSaveUri, getStartPosition(), vPlayerListener, mParentId, mIsHWCodec); } } break; case OPEN_START: mVideoLoadingText.setText(R.string.video_layout_loading); setVideoLoadingLayoutVisibility(View.VISIBLE); break; case OPEN_SUCCESS: loadVPlayerPrefs(); setVideoLoadingLayoutVisibility(View.GONE); setVideoLayout(); vPlayer.start(); attachMediaController(); break; case OPEN_FAILED: resultFinish(RESULT_FAILED); break; case BUFFER_START: setVideoLoadingLayoutVisibility(View.VISIBLE); vPlayerHandler.sendEmptyMessageDelayed(BUFFER_PROGRESS, 1000); break; case BUFFER_PROGRESS: if (vPlayer.getBufferProgress() >= 100) { setVideoLoadingLayoutVisibility(View.GONE); } else { mVideoLoadingText.setText( getString( R.string.video_layout_buffering_progress, vPlayer.getBufferProgress())); vPlayerHandler.sendEmptyMessageDelayed(BUFFER_PROGRESS, 1000); stopPlayer(); } break; case BUFFER_COMPLETE: setVideoLoadingLayoutVisibility(View.GONE); vPlayerHandler.removeMessages(BUFFER_PROGRESS); break; case CLOSE_START: mVideoLoadingText.setText(R.string.closing_file); setVideoLoadingLayoutVisibility(View.VISIBLE); break; case CLOSE_COMPLETE: mCloseComplete = true; break; case HW_FAILED: if (mVideoView != null) { mVideoView.setVisibility(View.GONE); mVideoView.setVisibility(View.VISIBLE); mVideoView.initialize(VideoActivity.this, VideoActivity.this, false); } break; case LOAD_PREFS: loadVPlayerPrefs(); break; } }
@Override public int getBufferPercentage() { if (isInitialized()) return (int) (vPlayer.getBufferProgress() * 100); return 0; }
/** * Fill a group and returns the group filled but not saved. * * @param aGroup a group to fill * @return the group with real participants */ public GroupEntity fillGroup(final GroupEntity aGroup) { if (aGroup != null) { // First get the tournament final TournamentEntity theTournament = aGroup.getStage().getTournament(); final boolean isTeam = theTournament.getIsTeamTournament(); // Get players or teams list List<TeamEntity> teamsTournament = null; List<PlayerEntity> playersTournament = null; if (isTeam) { teamsTournament = teamService.getSortedListTeam(theTournament.getTeams(), SortType.RANKING_POINTS); } else { playersTournament = playerService.getSortedListPlayer(theTournament.getPlayers(), SortType.RANKING_POINTS); } // Loop over the participant of the group for (final EffectiveParticipantEntity aParticipant : aGroup.getParticipants()) { final GroupRankReference theReference = aParticipant.getInitialReference(); final GroupEntity groupReference = theReference.getGroup(); final StageEntity stageReference = theReference.getStage(); final Integer rank = theReference.getRank(); if (groupReference == null && stageReference == null) { // Get the real participant from tournament ParticipantEntity realParticipant = null; if (isTeam) { realParticipant = teamsTournament.get(rank - 1); } else { realParticipant = playersTournament.get(rank - 1); } aParticipant.setParticipant(realParticipant); } else if (groupReference == null && stageReference != null) { // Get from stage if (stageReference.getGroups() != null) { for (final GroupEntity groupReferenceStage : stageReference.getGroups()) { final List<EffectiveParticipantEntity> participants = groupReferenceStage.getParticipants(); for (final EffectiveParticipantEntity previousParticipant : participants) { final Integer finalRankStage = previousParticipant.getFinalRankStage() != null ? previousParticipant.getFinalRankStage() : 0; if (finalRankStage == rank) { aParticipant.setParticipant(previousParticipant.getParticipant()); break; } } } } } else { // Get from group final List<EffectiveParticipantEntity> participants = groupReference.getParticipants(); for (final EffectiveParticipantEntity previousParticipant : participants) { final Integer finalRank = previousParticipant.getFinalRank() != null ? previousParticipant.getFinalRank() : 0; if (finalRank == rank) { aParticipant.setParticipant(previousParticipant.getParticipant()); break; } } } } } else { final GroupEntity emptyGroup = new GroupEntity(); emptyGroup.setParticipants(new ArrayList<EffectiveParticipantEntity>()); return emptyGroup; } return aGroup; }
private boolean isInitialized() { return (mCreated && vPlayer != null && vPlayer.isInitialized()); }
@Override public long getCurrentPosition() { if (isInitialized()) return vPlayer.getCurrentPosition(); return (long) (getStartPosition() * vPlayer.getDuration()); }
@Override public void onBufferComplete() { player_back.setVisibility(View.GONE); vPlayerHandler.sendEmptyMessage(BUFFER_COMPLETE); if (vPlayer != null && !vPlayer.needResume()) startPlayer(); }