
it.tidalwave.mobile.android.media.impl.AndroidMediaPlayerController Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* $Id: AndroidMediaPlayerController.java,v 6b982ff87c62 2010/06/26 19:11:24 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.mobile.android.media.impl;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import android.media.MediaPlayer;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.mobile.media.MediaPlayer.Controller;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class AndroidMediaPlayerController implements Controller
{
private static final String CLASS = AndroidMediaPlayerController.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
private MediaPlayer player;
// private final OnCompletionListener onCompletionListener = new MediaPlayer.OnCompletionListener()
// {
// public void onCompletion (final @Nonnull MediaPlayer mediaPlayer)
// {
// }
// };
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public AndroidMediaPlayerController (final @Nonnull MediaPlayer player)
{
this.player = player;
// player.setOnCompletionListener(onCompletionListener);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void start()
{
if (player != null)
{
player.start();
}
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void stop()
{
if (player != null)
{
player.stop();
}
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void pause()
{
if (player != null)
{
player.pause();
}
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Nonnegative
public int getDuration()
{
return (player == null) ? 0 : player.getDuration();
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Nonnegative
public int getPosition()
{
return (player == null) ? 0 : player.getCurrentPosition();
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void setPosition (final @Nonnegative int position)
{
if (player != null)
{
player.seekTo(position);
}
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public boolean isPlaying()
{
return (player == null) ? false : player.isPlaying();
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void dispose()
{
if (player != null)
{
logger.info("Disposing player %s", player);
player.release();
player.setOnCompletionListener(null);
player = null;
logger.info(">>>> disposed");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy