int getDuration() const;
bool hasMedia() const;
- bool hasInvalidMedia() const;
+ bool hasInvalidFiles() const;
bool hasVideo() const;
bool hasAudio() const;
bool hasAnimation() const;
bool m_HasAudio;
SmilImageItemView *m_pImageItem;
std::list<std::string> m_Attachments;
- bool m_HasInvalidMedia;
+ bool m_HasInvalidFiles;
};
}
void setListener(ISmilPlayerListener *l);
State getState() const;
- bool isPlayFinished();
void start();
void stop();
void reset();
virtual void onBeforeDelete(View &view);
private:
- void playPage();
+ bool playPage();
+ bool canPlay(SmilPage *page);
void startMedia();
void stopMedia();
void prepareMedia();
void showUnableToPlayVideoNotif();
void showUnableToPlayAudioNotif();
void showNotSupportedFileNotif();
+ void showUnableToPlayNotif(SmilPage &page);
private:
ISmilPlayerListener *m_pListener;
unsigned m_CurrentPageIndex;
int m_Duration;
State m_State;
- bool m_Finished;
int m_PageTickCounter;
};
, m_pVideoSink(nullptr)
, m_HasAudio(false)
, m_pImageItem(nullptr)
- , m_HasInvalidMedia(false)
+ , m_HasInvalidFiles(false)
{
build(page);
}
, m_pVideoSink(nullptr)
, m_HasAudio(false)
, m_pImageItem(nullptr)
- , m_HasInvalidMedia(false)
+ , m_HasInvalidFiles(false)
{
build(list);
}
return !m_MediaPath.empty();
}
-bool SmilPage::hasInvalidMedia() const
+bool SmilPage::hasInvalidFiles() const
{
- return m_HasInvalidMedia;
+ return m_HasInvalidFiles;
}
bool SmilPage::hasVideo() const
void SmilPage::buildImage(const MsgMedia &media)
{
m_pImageItem = new SmilImageItemView(getBox(), media.getFilePath());
- m_HasInvalidMedia = m_pImageItem->getImage() == nullptr;
+ m_HasInvalidFiles = m_pImageItem->getImage() == nullptr;
m_pImageItem->show();
appendItem(*m_pImageItem);
}
int duration = MediaUtils::getDurationSec(m_MediaPath);
if(duration == 0)
{
- m_HasInvalidMedia = true;
+ m_HasInvalidFiles = true;
return;
}
int duration = MediaUtils::getDurationSec(m_MediaPath);
if(duration == 0)
{
- m_HasInvalidMedia = true;
+ m_HasInvalidFiles = true;
return;
}
if(m_Duration == 0)
if(width * height == 0)
{
MSG_LOG_ERROR("Wrong video dimension");
- m_HasInvalidMedia = true;
+ m_HasInvalidFiles = true;
return;
}
SmilVideoItemView *item = new SmilVideoItemView(getBox(), width, height);
, m_CurrentPageIndex(0)
, m_Duration(0)
, m_State(StopState)
- , m_Finished(false)
, m_PageTickCounter(0)
{
create(mms);
m_pTimer = nullptr;
if(!nextPage())
- {
stop();
- m_Finished = true;
- }
-
return false;
}
return true;
return m_State;
}
-bool SmilPlayer::isPlayFinished()
-{
- return m_Finished;
-}
-
void SmilPlayer::start()
{
if(m_pTimer)
{
- MSG_LOG("Continue");
-
- setState(PlayState);
- continueTimer();
- startMedia();
+ if(canPlay(getCurrentPage()))
+ {
+ MSG_LOG("Continue");
+ setState(PlayState);
+ continueTimer();
+ startMedia();
+ }
}
else
{
MSG_LOG("Restart");
-
reset();
- setState(PlayState);
- playPage();
+ if(canPlay(getCurrentPage()))
+ {
+ setState(PlayState);
+ playPage();
+ }
}
}
void SmilPlayer::reset()
{
stop();
- m_Finished = false;
m_CurrentPageIndex = 0;
m_PageTickCounter = 0;
}
-void SmilPlayer::playPage()
+bool SmilPlayer::playPage()
{
- m_Finished = false;
SmilPage *page = getCurrentPage();
+ if(!page)
+ return false;
+
SmilPlayerView::displayPage(*page);
- if(page->hasInvalidMedia())
+ startTimer(page->getDuration());
+
+ if(page->hasMedia())
+ {
+ prepareMedia();
+ if(!canPlay(page))
+ {
+ stop();
+ showUnableToPlayNotif(*page);
+ return false;
+ }
+ startMedia();
+ }
+
+ if(page->hasInvalidFiles())
showNotSupportedFileNotif();
- prepareMedia();
- startMedia();
- startTimer(page->getDuration());
if(m_pListener)
m_pListener->onSmilPlayerPageChanged();
+
+ return true;
}
void SmilPlayer::prepareMedia()
{
if(m_MediaPlayer)
+ {
m_MediaPlayer->stop();
+ m_MediaPlayer->setPosition(0);
+ }
SmilPage *page = getCurrentPage();
if(page->hasMedia())
Evas_Object *videoSink = page->getVideoSink();
m_MediaPlayer->setDisplay(videoSink);
}
-
}
void SmilPlayer::stopMedia()
{
if(m_MediaPlayer)
m_MediaPlayer->pause();
- getCurrentPage()->playAnimation(false);
+ SmilPage *page = getCurrentPage();
+ if(page)
+ page->playAnimation(false);
+}
+
+bool SmilPlayer::canPlay(SmilPage *page)
+{
+ if(!page)
+ return false;
+
+ if(page->hasMedia() && m_MediaPlayer && !m_MediaPlayer->getFocus())
+ {
+ showUnableToPlayNotif(*page);
+ return false;
+ }
+ return true;
}
void SmilPlayer::startMedia()
{
- if(m_MediaPlayer && getCurrentPage()->hasMedia())
+ SmilPage *page = getCurrentPage();
+ if(!page)
+ return;
+
+ if(page->hasMedia() && m_MediaPlayer)
m_MediaPlayer->start();
- getCurrentPage()->playAnimation(true);
+ page->playAnimation(true);
}
double SmilPlayer::getPosition() const
{
if(probeNextPage())
{
+ stopMedia();
++m_CurrentPageIndex;
playPage();
return true;
{
if(probePrevPage())
{
+ stopMedia();
--m_CurrentPageIndex;
playPage();
return true;
notification_status_message_post(msg("IDS_MSG_TPOP_CANT_PREVIEW_FILE_FILE_FORMAT_NOT_SUPPORTED").cStr());
}
+void SmilPlayer::showUnableToPlayNotif(SmilPage &page)
+{
+ if(page.hasVideo())
+ showUnableToPlayVideoNotif();
+ else if(page.hasAudio())
+ showUnableToPlayAudioNotif();
+}
+
void SmilPlayer::onBeforeDelete(View &view)
{
MSG_LOG("");
void SmilPlayer::onMediaPlayerSoundFocusChanged()
{
- if(m_MediaPlayer->isPlaying() && m_MediaPlayer->isFocusChangedCallReason())
+ if(m_MediaPlayer->isPlaying() && !m_MediaPlayer->getFocus())
{
SmilPage *page = getCurrentPage();
if(page)
{
- m_MediaPlayer->pause();
- if(page->hasVideo())
- showUnableToPlayVideoNotif();
- else if(page->hasAudio())
- showUnableToPlayAudioNotif();
if(page->hasMedia())
+ {
+ showUnableToPlayNotif(*page);
stop();
+ }
}
}
}
#define MediaPlayer_h_
#include <player.h>
+#include <sound_manager.h>
#include <string>
#include <Evas.h>
void setPosition(int msec);
static int getDuration(const std::string &uri);
bool getFocus() const;
- bool isFocusChangedCallReason() const;
private:
static void on_completed_cb(void *user_data);
static void on_seek_cb(void *user_data);
- // Cll from media internal thread:
- static void on_sound_stream_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask,
- sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason,
- const char *extra_info, void *user_data);
+ // Call from media internal thread:
+ static void on_sound_stream_focus_state_changed_cb(sound_stream_info_h stream_info,
+ sound_stream_focus_change_reason_e reason,
+ const char *extra_info,
+ void *user_data);
player_state_e getState() const;
private:
player_h m_Player;
IMediaPlayerListener *m_pListener;
- bool m_Focus;
- bool m_FocusCallReason;
-
- int m_SoundManagerCallbackId;
+ sound_stream_info_h m_StreamInfo;
};
class IMediaPlayerListener
#include "Logger.h"
#include "CallbackAssist.h"
-#include <sound_manager.h>
#include <Ecore.h>
using namespace Msg;
MediaPlayer::MediaPlayer()
: m_Player()
, m_pListener(nullptr)
- , m_Focus(false)
- , m_FocusCallReason(false)
- , m_SoundManagerCallbackId(-1)
+ , m_StreamInfo()
{
- sound_manager_add_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_PLAYBACK,
- on_sound_stream_focus_state_watch_cb, this, &m_SoundManagerCallbackId);
-
- MSG_LOG("callback-id = ", m_SoundManagerCallbackId);
- player_create(&m_Player);
- player_set_sound_type(m_Player, SOUND_TYPE_MEDIA);
- player_set_volume(m_Player, 1.0, 1.0);
- player_set_looping(m_Player, false);
- player_set_completed_cb(m_Player, on_completed_cb, this);
+ sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, on_sound_stream_focus_state_changed_cb, this, &m_StreamInfo);
+ if(m_StreamInfo)
+ {
+ player_create(&m_Player);
+ if(m_Player)
+ {
+ player_set_sound_type(m_Player, SOUND_TYPE_MEDIA);
+ player_set_volume(m_Player, 1.0, 1.0);
+ player_set_looping(m_Player, false);
+ player_set_audio_policy_info(m_Player, m_StreamInfo);
+ player_set_completed_cb(m_Player, on_completed_cb, this);
+ }
+ }
}
MediaPlayer::~MediaPlayer()
{
- sound_manager_remove_focus_state_watch_cb(m_SoundManagerCallbackId);
m_pListener = nullptr;
stop();
- player_unprepare(m_Player);
- player_destroy(m_Player);
+
+ if(m_StreamInfo)
+ sound_manager_destroy_stream_information(m_StreamInfo);
+
+ if(m_Player)
+ {
+ player_unprepare(m_Player);
+ player_destroy(m_Player);
+ }
}
void MediaPlayer::setDisplay(Evas_Object *obj)
bool MediaPlayer::getFocus() const
{
- return m_Focus;
-}
+ sound_stream_focus_change_reason_e acquiredBy = SOUND_STREAM_FOCUS_CHANGED_BY_MEDIA;
+ int flags = 0;
+ char *extraInfo = nullptr;
-bool MediaPlayer::isFocusChangedCallReason() const
-{
- return m_FocusCallReason;
+ if(sound_manager_get_current_playback_focus(&acquiredBy, &flags, &extraInfo) == SOUND_MANAGER_ERROR_NONE)
+ {
+ free(extraInfo);
+ return acquiredBy != SOUND_STREAM_FOCUS_CHANGED_BY_RINGTONE &&
+ acquiredBy != SOUND_STREAM_FOCUS_CHANGED_BY_VOIP &&
+ acquiredBy != SOUND_STREAM_FOCUS_CHANGED_BY_CALL;
+ }
+
+ return true;
}
void MediaPlayer::start()
{
+ sound_manager_acquire_focus(m_StreamInfo, SOUND_STREAM_FOCUS_FOR_PLAYBACK, nullptr);
if(getState() == PLAYER_STATE_IDLE)
player_prepare(m_Player);
void MediaPlayer::stop()
{
+ sound_manager_release_focus(m_StreamInfo, SOUND_STREAM_FOCUS_FOR_PLAYBACK, nullptr);
player_state_e state = getState();
if(state == PLAYER_STATE_PLAYING || state == PLAYER_STATE_PAUSED)
player_stop(m_Player);
void MediaPlayer::setPosition(int msec)
{
- player_set_play_position(m_Player, msec, true, on_seek_cb, this);
+ player_state_e state = getState();
+ if(state == PLAYER_STATE_PLAYING || state == PLAYER_STATE_PAUSED || state == PLAYER_STATE_READY)
+ player_set_play_position(m_Player, msec, true, on_seek_cb, this);
}
int MediaPlayer::getDuration(const std::string &uri)
MSG_LOG("");
}
-void MediaPlayer::on_sound_stream_focus_state_watch_cb(int id,
- sound_stream_focus_mask_e focus_mask,
- sound_stream_focus_state_e focus_state,
- sound_stream_focus_change_reason_e reason,
- const char *extra_info,
- void *user_data)
+void MediaPlayer::on_sound_stream_focus_state_changed_cb(sound_stream_info_h stream_info,
+ sound_stream_focus_change_reason_e reason,
+ const char *extra_info,
+ void *user_data)
{
- MSG_LOG("callback-id = ", id);
- MSG_LOG("Interrupted focus state = ", focus_state);
MSG_LOG("Interrupted focus change reason = ", reason);
-
auto *self = static_cast<MediaPlayer*>(user_data);
- if(id != self->m_SoundManagerCallbackId)
- return;
- self->m_Focus = focus_state == SOUND_STREAM_FOCUS_STATE_RELEASED;
- self->m_FocusCallReason = reason == SOUND_STREAM_FOCUS_CHANGED_BY_RINGTONE ||
- reason == SOUND_STREAM_FOCUS_CHANGED_BY_VOIP ||
- reason == SOUND_STREAM_FOCUS_CHANGED_BY_CALL;
-
- ecore_main_loop_thread_safe_call_sync
+ ecore_main_loop_thread_safe_call_async
(
- [](void *data)->void*
+ [](void *data)
{
auto *self = (MediaPlayer*)data;
if(self->m_pListener)
self->m_pListener->onMediaPlayerSoundFocusChanged();
- return nullptr;
},
self
);