Playing Video in BlackBerry.
Hello everyone,
I have to write a Video Player for BlackBerry - as I run this file, it's working fine in my simulator, but if I replace: Class playerDemoClass = Class.forName("MultimediaDemo"); InputStream inputStream = playerDemoClass.getResourceAsStream("/man-cheetah-gazelle.3gp"); _player = Manager.createPlayer(inputStream, "video/3gp"); (Of course I had the file man-cheetah-gazelle.3gp added to project by using File-New-File-Advanced-Linked to Source-Browse.) with this: a http link then nothing is played. Can anyone help me? Thank you for anything, /** * MultimediaDemo.java * Copyright (C) 2001-2008 Research In Motion Limited. All rights reserved. */ import java.io.InputStream; import javax.microedition.media.Manager; import javax.microedition.media.MediaException; import javax.microedition.media.Player; import javax.microedition.media.PlayerListener; import javax.microedition.media.control.VideoControl; import javax.microedition.media.control.VolumeControl; import net.rim.device.api.system.Characters; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.MenuItem; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.Dialog; import net.rim.device.api.ui.component.EditField; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.component.Menu; import net.rim.device.api.ui.container.MainScreen; public final class MultimediaDemo extends UiApplication { public static void main(String[] args) { // create a new instance of the application // and start the application on the event thread MultimediaDemo theApp = new MultimediaDemo(); theApp.enterEventDispatcher(); } public MultimediaDemo() { // display a new screen pushScreen(new VideoScreen()); } } // create a new screen that extends MainScreen, which provides // default standard behavior for BlackBerry applications final class VideoScreen extends MainScreen implements PlayerListener { // declare variables for later use private Player _player; private VideoControl _videoControl; private VideoManager _videoManager; private Field _videoField; private int _currentVolume; public VideoScreen() { // invoke the MainScreen constructor super(); // add a screen title LabelField title = new LabelField("Multimedia Demo!", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); setTitle(title); // Initialize _currentVolume _currentVolume = 50; // display current Player volume // _volumeField = new EditField("Volume: ", "" + _currentVolume, 20, EditField.READONLY); // add(_volumeField); try { Class playerDemoClass = Class.forName("MultimediaDemo"); InputStream inputStream = playerDemoClass.getResourceAsStream("/man-cheetah-gazelle.3gp"); _player = Manager.createPlayer(inputStream, "video/3gp"); // Realize Player _player.realize(); // Add listener to catch Player events _player.addPlayerListener(this); // Get the Player VideoControl _videoControl = (VideoControl) _player.getControl("VideoControl"); // Initialize video display mode _videoField = (Field) _videoControl.initDisplayMode(VideoControl.USE_GUI _PRIMITIVE, "net.rim.device.api.ui.Field"); // Set the video display size to 200 x 200 // Create a manager for the video field _videoManager = new VideoManager(); _videoManager.add(_videoField); add(_videoManager); // Set video control to visible _videoControl.setVisible(true); // Start the Player _player.start(); // Set up Player volume setVolume(_currentVolume); } catch (Exception e) { System.out.println("foo" + e.getClass()); } } // override onClose() to cleanup Player resources and display a dialog box // when the application is closed public boolean onClose() { // Cleanup Player resources // try block try { // Stop Player _player.stop(); } // catch MediaException catch (MediaException e) { e.printStackTrace(); } if (_player != null) { // Close Player _player.close(); _player = null; } Dialog.alert("Goodbye!"); System.exit(0); return true; } // set the volume level for the Player private void setVolume(int level) { // get the Player volume control and set the volume level VolumeControl volumeControl = (VolumeControl) _player.getControl("VolumeControl"); volumeControl.setLevel(level); // Update _volumeField // _volumeField.setText("" + level); } // increase the Player volume by 10 private void volumeUp() { _currentVolume += 10; // Set _currentVolume to a valid value if it's out of range if (_currentVolume > 100) { _currentVolume = 100; } // Set Player volume to _currentVolume setVolume(_currentVolume); } // decrease the Player volume by 10 private void volumeDown() { _currentVolume -= 10; // Set _currentVolume to a valid value if it's out of range if (_currentVolume < 0) { _currentVolume = 0; } // Set Player volume to _currentVolume setVolume(_currentVolume); } // create a menu item for switching Player to full screen mode private MenuItem _fullScreen = new MenuItem("Full Screen", 200000, 10) { public void run() { // try block try { // switch Player to full screen mode _videoControl.setDisplayFullScreen(true); } // catch MediaException catch (MediaException e) { e.printStackTrace(); } } }; // create a menu item for users to pause and resume playback private MenuItem _pauseItem = new MenuItem("Pause/Resume", 200000, 10) { public void run() { // Start or stop the Player based on the Player state // try block try { // if current Player state is STARTED stop the Player if (_player.getState() == Player.STARTED) { _player.stop(); } // else if current Player state is PREFETCHED start the Player else if (_player.getState() == Player.PREFETCHED) { _player.start(); } } // catch MediaException catch (MediaException e) { e.printStackTrace(); } } }; // create a menu item for users to close the application private MenuItem _closeItem = new MenuItem("Close", 200000, 10) { public void run() { onClose(); } }; // override makeMenu to add the new menu items protected void makeMenu(Menu menu, int instance) { menu.add(_pauseItem); menu.add(_fullScreen); menu.add(_closeItem); } // override keyControl to handle volume up and down key presses protected boolean keyControl(char c, int status, int time) { // Handle volume up and down key presses to adjust Player volume // if volume up is pressed call volumeUp() if (c == Characters.CONTROL_VOLUME_UP) { volumeUp(); return true; } // else if volume down key is pressed call volumeDown() else if (c == Characters.CONTROL_VOLUME_DOWN) { volumeDown(); return true; } // else call the default keyControl handler of the super class else { return super.keyControl(c, status, time); } } // catch Player events and display them in the _eventField public void playerUpdate(Player player, String event, Object eventData) { // Update _eventField with the current event // _eventField.setText(event); } } // Manager to lay out the Player _videoField on the VideoScreen final class VideoManager extends net.rim.device.api.ui.Manager { public VideoManager() { super(0); } // lay out the _videoField on the screen based on it's preferred width and height protected void sublayout(int width, int height) { if (getFieldCount() > 0) { Field videoField = getField(0); layoutChild(videoField, videoField.getPreferredWidth(), videoField.getPreferredHeight()); } setExtent(width, height); } } |
I am not allowed to post a link so the replacement is empty:
but it is _player = Manager.createPlayer("http link to a 3gp file here "); |
When not allowed ppl use it this way: "h t t p : / /...." ;-)
Next, you still should use PHP Code:
Blackberry Bold 9000 Streaming mp4/3gp video fail. - Java Development - BlackBerry Support Community Forums And last. You start playback righ away in constructor which maybe OK for the local file. But when it comes to internet streaming you better have command for it, and run it as a separate thread 8-) |
Hi,
I'm also making an application which plays a video. I also had the same method in playing a video. Now, I was able to play the video on the device simulator using the sample video located at "file:///store/samples/videos/BlackBerry.mp4". I don't have any problems/issues at all on the device simulator. In other words, it is working perfectly just as I wanted. But when I run it now on my device, which is a Blackberry 8820 BTW, the video doesn't play. Even though I already had the directory "file:///store/samples/videos/BlackBerry.mp4" on my device. I also tried using other directory such as "file:///store/home/user/videos/BlackBerry.mp4", "file:///SDCard/Videos/BlackBerry.mp4", and "file:///SDCard/BlackBerry/videos/BlackBerry.mp4" but still the video doesn't play. And of course, I had the file on each said directories. Can you help me with this one? What seems to be the problem? Thanks guys in advance. |
Hi again,
I got something unusual. I checked all the directories listed a while ago using this code: Code:
FileConnection fsC = (FileConnection)Connector.open(videoURL); Now, I tracked the behavior of my application when playing video and here is the result. The Code below used to initialize the media I am going to play: Code:
private void initializeMedia() Now, my question is that how come that my VideoControl (variable vc) is getting NULL values when my directories/URL pointing to the video I want to play is VALID? I hope you can help me now with this one. Thanks! |
All times are GMT -5. The time now is 07:30 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.