Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 6
Registered: ‎05-28-2009
My Device: Not Specified

Blackberry Bold 9000 Streaming mp4/3gp video fail.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dyanmic;

import java.util.Hashtable;
import java.util.Enumeration;

import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Alert;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.CommandListener;

import javax.microedition.media.Player;
import javax.microedition.media.Manager;
import javax.microedition.media.PlayerListener;

import javax.microedition.media.control.VideoControl;
//import javax.microedition.media.protocol.DataSource;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.media.*;

/**
 *
 * @author Owner
 */
class PlayerManager implements Runnable, CommandListener, PlayerListener {

  Form form;
  List list;
  Player player;
  String locator;
  Display display;

  private Command stopCommand;
  private Command pauseCommand;
  private Command startCommand;
 private ServerObserver observer;
  public PlayerManager(Form form, List list, String locator, Display display,ServerObserver Observer) {
  this.form = form;
  this.list = list;
  this.locator = locator;
  this.display = display;
this.observer=Observer;
    // stop, pause and restart commands
    stopCommand = new Command("Stop", Command.STOP, 1);
    pauseCommand = new Command("Pause", Command.ITEM, 1);
    startCommand = new Command("Start", Command.ITEM, 1);

    // the form acts as the interface to stop and pause the media
    form.addCommand(stopCommand);
    form.addCommand(pauseCommand);
  }

  public void run() {

    try {
      // since we are loading data over the network, a delay can be
      // expected
      Alert alert = new Alert("Loading. Please wait ....");
      //locator="rtsp://stream.zoovision.com/musicvideos/well_make_a_lover_of_you.3gp";
        locator="rtsp://portal.menacast.com:8080/3GP/2000_4a09ba30-0905131905.3gp";

locator="http://portal.menacast.com/MediaSphere/videos/MP4/2000_4a09ba30-0905131905.mp4";
      //locator="http://www.craftbits.com/j2me/siren.wav";     
       alert.setTimeout(Alert.FOREVER);
       display.setCurrent(alert);
       this.observer.trace(locator);
       this.observer.trace("Player Created:"+locator);      
       this.observer.trace("SupportedContentTypes:"+Manager.getSupportedContentTypes("rtsp"));
       this.observer.trace("SupportedProtocols:"+Manager.getSupportedProtocols("rtsp"));
      
       player = Manager.createPlayer(locator);      
       //player = Manager.createPlayer(urlToStream(locator),"video/3gpp");
      
     // player = Manager.createPlayer(getClass().getResourceAsStream(locator), "video/3gpp");
      // player = Manager.createPlayer(getClass().getResourceAsStream(locator),"");
      
      // a listener to handle player events like starting, closing etc
    
      player.addPlayerListener(this);
      //player.setMediaTime(50);
      player.setLoopCount(-1); // play indefinitely
      //player.prefetch(); // prefetch
      player.realize(); // realize
VideoControl vc = null;
      if((vc = (VideoControl)player.getControl("VideoControl")) != null) {
        Item videoDisp =
          (Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null);
        form.append(videoDisp);
      }

      display.setCurrent(form);
      player.start(); // and start
    } catch(Exception e) {
      System.err.println("run:"+e);
      e.printStackTrace();
    }
  }

  public void commandAction(Command command, Displayable disp) {
    if(disp instanceof Form) {
      // if showing form, means the media is being played
      // and the user is trying to stop or pause the player
      try {
        if(command == stopCommand) { // if stopping the media play
          player.close(); // close the player
          display.setCurrent(list); // redisplay the list of media
          form.removeCommand(startCommand); // remove the start command
          form.removeCommand(pauseCommand); // remove the pause command
          form.removeCommand(stopCommand);  // and the stop command
        } else if(command == pauseCommand) { // if pausing
          player.stop(); // pauses the media, note that it is called stop
          form.removeCommand(pauseCommand); // remove the pause command
          form.addCommand(startCommand); // add the start (restart) command
        } else if(command == startCommand) { // if restarting
          player.start(); // starts from where the last pause was called
          form.removeCommand(startCommand);
          form.addCommand(pauseCommand);
        }
      } catch(Exception e) {
        System.err.println(e);
      }
    }
  }
void defplayer() throws MediaException {
      if (player != null) {
         if(player.getState() == Player.STARTED) {
            player.stop();
         }
         if(player.getState() == Player.PREFETCHED) {
            player.deallocate();
         }
         if(player.getState() == Player.REALIZED ||
            player.getState() == Player.UNREALIZED) {
            player.close();
         }
      }
      player = null;
   }

  /* Handle player events */
  public void playerUpdate(Player player, String event, Object eventData) {

    // if the event is that the player has started, show the form
    // but only if the event data indicates that the event relates to newly
    // stated player, as the STARTED event is fired even if a player is
    // restarted. Note that eventData indicates the time at which the start
    // event is fired.
    if(event.equals(PlayerListener.STARTED) &&
          new Long(0L).equals((Long)eventData)) {

      // see if we can show a video control, depending on whether the media
      // is a video or not
      VideoControl vc = null;
      if((vc = (VideoControl)player.getControl("VideoControl")) != null) {
        Item videoDisp =
          (Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null);
        form.append(videoDisp);
      }

      display.setCurrent(form);
    } else if(event.equals(PlayerListener.CLOSED)) {

    // form.deleteAll(); // clears the form of any previous controls
    }
  }
  private InputStream urlToStream(String url) throws IOException
    {
        // Open connection to the http url...
        HttpConnection connection = (HttpConnection) Connector.open(url);
        DataInputStream dataIn = connection.openDataInputStream();
        byte[] buffer = new byte[1000];
        int read = -1;
        // Read the content from url.
        ByteArrayOutputStream byteout = new ByteArrayOutputStream();
        while ((read = dataIn.read(buffer)) >= 0)
        {
            byteout.write(buffer, 0, read);
        }
        dataIn.close();
        // Fill InputStream to return with content read from the URL.
        ByteArrayInputStream byteIn = new ByteArrayInputStream(byteout
                .toByteArray());
        return byteIn;

    }

}

mp4 Video codec detail.

 

 

Video: Stream 0

=============

Codec: mp4v

Resolution : 320X180

Frame Rate: 25

 

Audio Stream 1

==========

Codec mp4a

Type : audio

Channels :2

Sample Rate: 32000 MHZ

BPS : 16

Bitrate: 1024 kb/s

 

 

 

 

 

Can some advice what need to do fix this issue.

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Blackberry Bold 9000 Streaming mp4/3gp video fail.

Are you getting exceptions?

Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 6
Registered: ‎05-28-2009
My Device: Not Specified

Re: Blackberry Bold 9000 Streaming mp4/3gp video fail.

Hi ,

 

There is no exception , just loading message , it waiting longer time nothing happen.

 

Thanks

Praful

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Blackberry Bold 9000 Streaming mp4/3gp video fail.

Check with the url which you passing. Following example allows me to play video from the web.

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/1089414/How_To...


Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 45
Registered: ‎08-29-2013
My Device: Blackberry curve-9360 and Blackberry bold-9860
My Carrier: Company

Re: Blackberry Bold 9000 Streaming mp4/3gp video fail.

[ Edited ]

The link you show

 

"http://btsc.webapps.blackberry.com/btsc/fetch/2000/348583/800332/1089414/How_To_-_Play_video_within_...

 

opens blank page.
Please suggest.

Thanks in advance.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry Bold 9000 Streaming mp4/3gp video fail.