Guide de développement
Local Navigation
- Utilisation de l'audio sur un terminal BlackBerry
- Utilisation de la vidéo sur un terminal BlackBerry
- Utilisation d'images sur un terminal BlackBerry
- Propriétés d'enregistrement multimédia
- Changement de flux multimédia avec le protocole RTSP
- Pour plus d'informations
- Envoi de commentaires
- Historique de révision du document
- Informations juridiques
Documentation produit
>
Documentation pour les développeurs
>
Guides de développement et référence API pour Java
>
Guide de développement
Multimedia - BlackBerry Java SDK - 7.0
Lire une vidéo dans un champ d'interface utilisateur depuis une application de terminal BlackBerry
- Importez les classes et les interfaces requises.
import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import java.io.*; import javax.microedition.media.*; import javax.microedition.media.control.*;
- Créez le cadre d'application en développant la classe UiApplication. Dans main(), créez une instance de la nouvelle classe et appelez enterEventDispatcher() pour activer l'application et recevoir des événements. Dans le constructeur d'application, appelez pushScreen() pour afficher l'écran personnalisé de l'application. La classe VideoPlaybackDemoScreen, décrite à l'étape 3, représente l'écran personnalisé.
public class VideoPlaybackDemo extends UiApplication { public static void main(String[] args) { VideoPlaybackDemo app = new VideoPlaybackDemo(); app.enterEventDispatcher(); } public VideoPlaybackDemo() { pushScreen(new VideoPlaybackDemoScreen()); } } - Créez le cadre de l'écran personnalisé en développant la classe MainScreen.
private class VideoPlaybackDemoScreen extends MainScreen { public VideoPlaybackDemoScreen() { } } - Avec le constructeur d'écran, dans un bloc try/catch, créez une instance de la classe Player en appelant Manager.createPlayer(String), en transmettant l'emplacement du fichier vidéo à lire.
try { Player player = javax.microedition.media.Manager.createPlayer("file:///SDCard/BlackBerry/videos/soccer1.avi"); } catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); } - Pour contrôler un aspect précis de la lecture, récupérez l'objet Control approprié. Appelez d'abord la méthode realize() de l'objet Player pour accéder à son objet Control associé. Appelez ensuite Player.getControl()
en transmettant VideoControl à la chaîne pour récupérer l'objet VideoControl associé à Player.
try { Player player = javax.microedition.media.Manager.createPlayer("file:///SDCard/BlackBerry/videos/soccer1.avi"); player.realize(); VideoControl videoControl = (VideoControl) player.getControl("VideoControl"); } catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); } - Appelez VideoControl.initDisplayMode(int mode, Object arg) pour initialiser le mode utilisé par un champ vidéo. Transmettez un paramètre arg pour indiquer l'interface utilisateur primitive lisant la vidéo. Convertissez l'objet renvoyé en objet Field. Remarque : Vous pouvez appeler initDisplayMode() de différentes façons pour renvoyer un objet Field ou pour qu'un objet Item lise une vidéo dans une classe Canvas dans un MIDlet.
try { Player player = javax.microedition.media.Manager.createPlayer("file:///SDCard/BlackBerry/videos/soccer1.avi"); player.realize(); VideoControl videoControl = (VideoControl) player.getControl("VideoControl"); Field videoField = (Field)videoControl.initDisplayMode( VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" ); } catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); } - Appelez add() pour ajouter l'objet Field renvoyé à votre objet Screen ou Manager.
try { Player player = javax.microedition.media.Manager.createPlayer("file:///SDCard/BlackBerry/videos/soccer1.avi"); player.realize(); VideoControl videoControl = (VideoControl) player.getControl("VideoControl"); Field videoField = (Field)videoControl.initDisplayMode( VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" ); add(videoField); } catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); } - Définissez le volume de lecture à l'aide de VolumeControl.setLevel(). Pour récupérer un objet VolumeControl associé à votre objet Player, appelez Player.getControl("VolumeControl").
try { Player player = javax.microedition.media.Manager.createPlayer("file:///SDCard/BlackBerry/videos/soccer1.avi"); player.realize(); VideoControl videoControl = (VideoControl) player.getControl("VideoControl"); Field videoField = (Field)videoControl.initDisplayMode( VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" ); add(videoField); VolumeControl volume = (VolumeControl) player.getControl("VolumeControl"); volume.setLevel(30); } catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); } - Appelez Player.start() pour démarrer la lecture.
try { Player player = javax.microedition.media.Manager.createPlayer("file:///SDCard/BlackBerry/videos/soccer1.avi"); player.realize(); VideoControl videoControl = (VideoControl) player.getControl("VideoControl"); Field videoField = (Field)videoControl.initDisplayMode( VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" ); add(videoField); VolumeControl volume = (VolumeControl) player.getControl("VolumeControl"); volume.setLevel(30); player.start(); } catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); }
Sujet suivant: Échantillon de code : lecture vidéo dans un champ d'interface utilisateur depuis une application de terminal BlackBerry
Sujet précédent: Affichage d'images graphiques sur des champs vidéo
Ces informations vous ont-elles été utiles ? Envoyez-nous vos commentaires.