BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-27-2009, 04:20 AM   #1 (permalink)
New Member
 
Join Date: May 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Playing Video in BlackBerry.

Please Login to Remove!

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);
}
}
Offline  
Old 05-27-2009, 04:28 AM   #2 (permalink)
New Member
 
Join Date: May 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 ");
Offline  
Old 06-25-2009, 07:55 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2009
Location: CANADA
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 64
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

When not allowed ppl use it this way: "h t t p : / /...."
Next, you still should use
PHP Code:
_player Manager.createPlayer(inputStream"video/3gp"); 
but for inputStream look here:
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
Offline  
Old 06-30-2009, 01:10 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Sep 2008
Model: 7100T
PIN: N/A
Carrier: Carrier
Posts: 18
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Offline  
Old 06-30-2009, 03:06 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Sep 2008
Model: 7100T
PIN: N/A
Carrier: Carrier
Posts: 18
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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);
if(fsC.exists()){
   WriteLog("Video Exists");
} else {
   WriteLog("Video Dont Exists");
}
using this code, I verified that all of the directories I listed on my previous post exists. So let's forget about the directory issues for now, since it was confirmed that the directories I had been using is valid.

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()
    {         
        try
        {   
            /* For the purpose of this sample we are supplying a URL to a media file
            that is included in the project itself. 
            See the javax.microedition.media.Manager javadoc for more information on 
            handling data residing on a server.
            */
            _player = javax.microedition.media.Manager.createPlayer(videoURL);
            WriteLog("createPlayer");
            _player.setLoopCount(7);
            _player.realize();            
            WriteLog("realize");
            VideoControl vc = (VideoControl) _player.getControl("VideoControl");
            WriteLog("getControl");
            _videoField = (Field) vc.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
            vc.setVisible(true);
            WriteLog("setVisible");                    
        } catch(MediaException pe) {
            System.out.println(pe.toString());
            WriteLog("MediaException");
        } catch (IOException ioe) {
            System.out.println(ioe.toString());
            WriteLog("ioe");
        } catch (IllegalArgumentException iae) {
            System.out.println(iae.toString());            
            WriteLog("iae");
        }
So, as fas as my code tracking is concern, the codes colored with red are the ones that my application doesn't execute. Because on my log, the last thing that was logged was getControl. So it means that, either the variable vc is NULL or it has an exception. But as you can see on that code, I also log it when there's an exception, and on my log it doesn't have any exceptions. So probably, the variable vc is really has a NULL value.

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!
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.