|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description:This class provides duration of media file by parsing it |
|
15 * |
|
16 */ |
|
17 #include <MsgMediaResolver.h> |
|
18 #include <XQConversions.h> |
|
19 |
|
20 #include "msgmediautil.h" |
|
21 |
|
22 //--------------------------------------------------------------- |
|
23 // MsgMediaUtil::MsgMediaUtil |
|
24 // Constructor |
|
25 //--------------------------------------------------------------- |
|
26 MsgMediaUtil::MsgMediaUtil() |
|
27 { |
|
28 |
|
29 } |
|
30 |
|
31 //--------------------------------------------------------------- |
|
32 // MsgMediaUtil::MsgMediaUtil |
|
33 // Desctructor |
|
34 //--------------------------------------------------------------- |
|
35 MsgMediaUtil::~MsgMediaUtil() |
|
36 { |
|
37 |
|
38 } |
|
39 |
|
40 //--------------------------------------------------------------- |
|
41 // MsgMediaUtil::mediaDuration |
|
42 // @see header file |
|
43 //--------------------------------------------------------------- |
|
44 QString MsgMediaUtil::mediaDuration(const QString& mediaFile) |
|
45 { |
|
46 QString formattedDuration(" "); |
|
47 |
|
48 HBufC *name = XQConversions::qStringToS60Desc(mediaFile); |
|
49 TInt duration = 0; |
|
50 TRAPD(error, duration = mediaDurationL(*name)); |
|
51 delete name; |
|
52 |
|
53 if ( error ) |
|
54 return formattedDuration; |
|
55 |
|
56 int sec_duration = duration / 1000; |
|
57 int hour_component = sec_duration / (60*60); |
|
58 int min_component = (sec_duration - (hour_component*60*60))/60; |
|
59 int sec_component = (sec_duration - (hour_component*60*60) - (min_component*60)); |
|
60 |
|
61 if( hour_component > 0) |
|
62 { |
|
63 formattedDuration = QString("%1:%2:%3").arg(hour_component, 2, 10, QChar('0')). |
|
64 arg(min_component, 2, 10, QChar('0')).arg(sec_component, 2, 10, QChar('0')); |
|
65 } |
|
66 else |
|
67 { |
|
68 formattedDuration = QString("%1:%2").arg(min_component, 2, 10, QChar('0')). |
|
69 arg(sec_component, 2, 10, QChar('0')); |
|
70 } |
|
71 |
|
72 return formattedDuration; |
|
73 } |
|
74 |
|
75 //--------------------------------------------------------------- |
|
76 // MsgMediaUtil::mediaDurationL |
|
77 // @see header file |
|
78 //--------------------------------------------------------------- |
|
79 TInt MsgMediaUtil::mediaDurationL(const TDesC& mediaFile) |
|
80 { |
|
81 CMsgMediaResolver* resolver = CMsgMediaResolver::NewLC(); |
|
82 resolver->SetCharacterSetRecognition(EFalse); |
|
83 |
|
84 RFile rFile = resolver->FileHandleL(mediaFile); |
|
85 CleanupClosePushL( rFile ); |
|
86 |
|
87 CMsgMediaInfo* info = resolver->CreateMediaInfoL( rFile ); |
|
88 resolver->ParseInfoDetailsL(info, rFile); |
|
89 CleanupStack::PushL( info ); |
|
90 |
|
91 TInt duration = info->Duration(); |
|
92 |
|
93 CleanupStack::PopAndDestroy(3, resolver); // info, rFile, resolver |
|
94 |
|
95 return duration; |
|
96 } |
|
97 |
|
98 |
|
99 // EOF |
|
100 |