⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drmplayer.java

📁 public void playerUpdate(final Player p, final String event, final Object eventData) { // queue a
💻 JAVA
字号:
package com.model;

import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;

import com.btrend.viewclient.control.Application;
import com.btrend.viewclient.view.impl.VideoList;

/**
 * Player with DRM protected audio.
 */
public class DRMPlayer implements CommandListener, PlayerListener {
	private Player player;

	private Application midlet;

	private final Command stopCommand;

	private VideoList list;

	public DRMPlayer(Application midlet, VideoList list) {
		this.midlet = midlet;
		this.list = list;

		stopCommand = new Command("Stop", Command.ITEM, 2);
	}

	/**
	 * Releases resources
	 */
	public void releaseResources() {
		discardPlayer();
	}

	public void commandAction(Command cmd, Displayable disp) {
		if (cmd == stopCommand) {
			discardPlayer();
		}
	}

	public void playerUpdate(final Player p, final String event, final Object eventData) {
		// queue a call to updateEvent in the user interface event queue
		Display display = Display.getDisplay(midlet);
		display.callSerially(new Runnable() {
			public void run() {
				DRMPlayer.this.updateEvent(p, event, eventData);
			}
		});
	}

	public void stop() {
		if (player != null) {
			player.close();
		}
	}

	// Called in case of exception to make sure invalid players are closed
	private void discardPlayer() {
		if (player != null) {
			player.close();
			player = null;
		}
		list.getScreen().removeCommand(stopCommand);
	}

	private void updateEvent(Player p, String event, Object eventData) {
		if (event == END_OF_MEDIA) {
			discardPlayer();
		} else if (event == CLOSED) {
			player = null;
			list.getScreen().removeCommand(stopCommand);
		}
	}

	public void playDRMprotected(String file, String type) {
		if (file == null) {
			midlet.alertError("No file specified for type " + type);
		} else {
			try {
				player = Manager.createPlayer(file);
				player.addPlayerListener(this);
				player.realize();
				player.start();
				list.getScreen().addCommand(stopCommand);
			} catch (IllegalArgumentException iae) {
				discardPlayer();
				midlet.alertError("IllegalArgumentException: " + iae.getMessage() + " file: " + file);
			} catch (IOException ioe) {
				discardPlayer();
				midlet.alertError("IOException: " + ioe.getMessage() + " file: " + file);
			} catch (MediaException me) {
				discardPlayer();
				midlet.alertError("MediaException: " + me.getMessage() + " file: " + file);
			} catch (SecurityException se) {
				discardPlayer();
				midlet.alertError("SecurityException: " + se.getMessage() + " file: " + file);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -